< All Topics

Get Last Archive Error

Overview

The Get last archive error function provides detailed error information about the most recent archive operation that failed. This function is essential for implementing robust error handling and debugging archive-related issues in your Unreal Engine projects.

Function Description

Get Last Archive Error

  • Node Name: Get last archive error
  • Category: Archive Manager
  • Type: Synchronous (immediate operation)

Retrieves the error message from the most recent archive operation that failed. This function should be called immediately after a failed archive operation to get specific details about what went wrong.

Blueprint Usage

Parameters

ParameterTypeDescription
NoneThis function takes no input parameters
OutputTypeDescription
Return ValueStringDetailed error message describing the failure

Blueprint Setup Example

Basic Error Handling Pattern

  1. Perform Archive Operation: Use any archive function (Zip Files, Unzip Files, etc.)
  2. Check Return Value: Use Branch node to check if operation succeeded
  3. Handle Success: Connect True output to success logic
  4. Handle Failure: Connect False output to “Get last archive error”
  5. Display Error: Show error message to user or log for debugging

Error Handling Workflow

Zip Files
    ↓
Branch (Success?)
    ↓ (False)
Get last archive error
    ↓
Print String: "Archive Error: " + Error Message
    ↓ (True)
Print String: "Archive operation completed successfully"

Complete Error Handling Example

Event BeginPlay
    ↓
Make Array (File Paths)
    ↓
Zip Files
    ↓
Branch: Return Value
    ↓ (True Branch)
Print String: "Files zipped successfully"
    ↓ (False Branch)
Get last archive error
    ↓
Print String: "Zip failed: " + Error Message
    ↓
Display Error Dialog (optional)

C++ Usage

Basic Error Handling

Click to see the code
void BasicErrorHandlingCorrected()
    {
        // Fixed: Added template parameter
        TArray<FString> FilesToZip = {TEXT("C:/MyFile1.txt"), TEXT("C:/MyFile2.txt")};
        FString ZipPath = TEXT("C:/Output.zip");

        bool bSuccess = UArchiveManagerBPLibrary::ZipFiles(FilesToZip, ZipPath, false);

        if (!bSuccess)
        {
            FString ErrorMessage = UArchiveManagerBPLibrary::GetLastArchiveError();
            UE_LOG(LogTemp, Error, TEXT("Archive operation failed: %s"), *ErrorMessage);
            
            // Handle specific error types
            if (ErrorMessage.Contains(TEXT("access denied")))
            {
                UE_LOG(LogTemp, Error, TEXT("Insufficient permissions for archive operation"));
            }
            else if (ErrorMessage.Contains(TEXT("file not found")))
            {
                UE_LOG(LogTemp, Error, TEXT("One or more source files do not exist"));
            }
        }
        else
        {
            UE_LOG(LogTemp, Log, TEXT("Archive operation completed successfully"));
        }
    }

Advanced Error Handling System

Click to see the code
UCLASS()
    class YOURGAME_API UArchiveErrorHandler : public UObject
    {
        GENERATED_BODY()

    public:
        UFUNCTION(BlueprintCallable)
        static bool HandleArchiveError(const FString& Operation, bool bSuccess);
        
        UFUNCTION(BlueprintCallable)
        static FString GetUserFriendlyErrorMessage(const FString& TechnicalError);
        
        UFUNCTION(BlueprintCallable)
        static void LogArchiveError(const FString& Operation, const FString& ErrorMessage);

    private:
        static void DisplayErrorToUser(const FString& Operation, const FString& UserMessage);
    };

    bool UArchiveErrorHandler::HandleArchiveError(const FString& Operation, bool bSuccess)
    {
        if (!bSuccess)
        {
            FString ErrorMessage = UArchiveManagerBPLibrary::GetLastArchiveError();
            LogArchiveError(Operation, ErrorMessage);
            
            // Show user-friendly message
            FString UserMessage = GetUserFriendlyErrorMessage(ErrorMessage);
            DisplayErrorToUser(Operation, UserMessage);
            
            return false;
        }
        
        UE_LOG(LogTemp, Log, TEXT("%s completed successfully"), *Operation);
        return true;
    }

    FString UArchiveErrorHandler::GetUserFriendlyErrorMessage(const FString& TechnicalError)
    {
        if (TechnicalError.Contains(TEXT("access denied")) || TechnicalError.Contains(TEXT("permission")))
        {
            return TEXT("Unable to access the file or folder. Please check file permissions.");
        }
        else if (TechnicalError.Contains(TEXT("file not found")) || TechnicalError.Contains(TEXT("does not exist")))
        {
            return TEXT("One or more files could not be found. Please verify file paths.");
        }
        else if (TechnicalError.Contains(TEXT("disk full")) || TechnicalError.Contains(TEXT("space")))
        {
            return TEXT("Insufficient disk space to complete the operation.");
        }
        else if (TechnicalError.Contains(TEXT("corrupt")) || TechnicalError.Contains(TEXT("invalid")))
        {
            return TEXT("The archive file appears to be corrupted or invalid.");
        }
        else if (TechnicalError.Contains(TEXT("memory")))
        {
            return TEXT("Insufficient memory to complete the operation.");
        }
        else
        {
            return FString::Printf(TEXT("An unexpected error occurred: %s"), *TechnicalError);
        }
    }

    void UArchiveErrorHandler::LogArchiveError(const FString& Operation, const FString& ErrorMessage)
    {
        UE_LOG(LogTemp, Error, TEXT("Archive Error in %s: %s"), *Operation, *ErrorMessage);
        
        // Optional: Write to crash reports or analytics
        // Note: FAnalytics would need to be properly configured
        #if WITH_ANALYTICS
        // FAnalytics::RecordError(FString::Printf(TEXT("Archive_%s"), *Operation), ErrorMessage);
        #endif
    }

    void UArchiveErrorHandler::DisplayErrorToUser(const FString& Operation, const FString& UserMessage)
    {
        // Implementation depends on your UI system
        // For example, using on-screen messages:
        if (GEngine)
        {
            FString DisplayText = FString::Printf(TEXT("%s Error: %s"), *Operation, *UserMessage);
            GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, DisplayText);
        }
        
        // Or trigger a UI event for custom error dialogs
        // UGameplayStatics::GetPlayerController(GetWorld(), 0)->ClientMessage(UserMessage);
    }

Async Operation Error Handling

Click to expand the code
UCLASS()
    class YOURGAME_API UAsyncArchiveManager : public UObject
    {
        GENERATED_BODY()

    public:
        UFUNCTION(BlueprintCallable)
        void ZipFilesAsync(const TArray<FString>& FilePaths, const FString& OutputPath); // Fixed: Added <FString>

    private:
        UFUNCTION()
        void OnZipComplete(bool bSuccess, FString PathToZipFile); // Fixed: Added correct parameters
        
        FString CurrentOperation;
    };

    void UAsyncArchiveManager::ZipFilesAsync(const TArray<FString>& FilePaths, const FString& OutputPath)
    {
        // Validate inputs
        if (FilePaths.Num() == 0 || OutputPath.IsEmpty())
        {
            UE_LOG(LogTemp, Error, TEXT("Invalid parameters for async zip operation"));
            return;
        }

        CurrentOperation = TEXT("Async Zip Operation");
        
        // Setup progress delegate (optional)
        FZipProgressDelegate ProgressDelegate;
        ProgressDelegate.BindLambda([this](float Progress)
        {
            UE_LOG(LogTemp, VeryVerbose, TEXT("%s progress: %.1f%%"), *CurrentOperation, Progress * 100.0f);
        });
        
        // Setup completion callback with correct delegate type
        FZipTaskCompleteDelegate CompletionCallback;
        CompletionCallback.BindDynamic(this, &UAsyncArchiveManager::OnZipComplete);
        
        // Start async operation with correct API
        UZipTask* Task = UArchiveManagerBPLibrary::ZipFilesAsync(
            FilePaths, 
            OutputPath, 
            false, 
            ProgressDelegate,
            CompletionCallback
        );
        
        if (!Task)
        {
            FString ErrorMessage = UArchiveManagerBPLibrary::GetLastArchiveError();
            UE_LOG(LogTemp, Error, TEXT("Failed to start %s: %s"), *CurrentOperation, *ErrorMessage);
        }
        else
        {
            UE_LOG(LogTemp, Log, TEXT("Started %s with %d files"), *CurrentOperation, FilePaths.Num());
        }
    }

    void UAsyncArchiveManager::OnZipComplete(bool bSuccess, FString PathToZipFile)
    {
        if (!bSuccess)
        {
            FString ErrorMessage = UArchiveManagerBPLibrary::GetLastArchiveError();
            UE_LOG(LogTemp, Error, TEXT("%s failed: %s"), *CurrentOperation, *ErrorMessage);
            
            // Handle error (notify UI, retry logic, etc.)
            UArchiveErrorHandler::HandleArchiveError(CurrentOperation, false);
        }
        else
        {
            UE_LOG(LogTemp, Log, TEXT("%s completed successfully: %s"), *CurrentOperation, *PathToZipFile);
        }

        CurrentOperation.Empty(); // Clear current operation
    }

Common Error Messages

File System Errors

  • “File not found”: Source file doesn’t exist at specified path
  • “Access denied”: Insufficient permissions to read/write files
  • “Path too long”: File path exceeds system limits
  • “Disk full”: Insufficient storage space for operation
  • “File in use”: File is locked by another process

Archive-Specific Errors

  • “Invalid archive”: Archive file is corrupted or not a valid zip
  • “Unsupported compression”: Archive uses unsupported compression method
  • “Archive too large”: Archive exceeds maximum supported size
  • “Invalid password”: Incorrect password for encrypted archive
  • “Compression failed”: Error during compression process

Memory and Resource Errors

  • “Out of memory”: Insufficient RAM for operation
  • “Too many open files”: System file handle limit exceeded
  • “Operation cancelled”: User or system cancelled the operation
  • “Timeout”: Operation took too long to complete

Best Practices

Error Handling Guidelines

  • Always check return values: Never ignore the success/failure status
  • Call immediately after failure: Get error message right after failed operation
  • Provide user feedback: Show meaningful error messages to users
  • Log for debugging: Record errors for troubleshooting
  • Implement retry logic: Some errors may be temporary

Integration Examples

Blueprint Error Dialog System

Archive Operation (Any)
    ↓
Branch: Success?
    ↓ (False)
Get last archive error
    ↓
Create Widget: Error Dialog
    ↓
Set Error Message Text
    ↓
Add to Viewport
    ↓ (True)
Print String: "Operation successful"

Automatic Retry System

Custom Event: Try Archive Operation
    ↓
Archive Function
    ↓
Branch: Success?
    ↓ (False)
Get last archive error
    ↓
Branch: Should Retry? (Max 3 attempts)
    ↓ (True)
Delay (1 second)
    ↓
Call Event: Try Archive Operation
    ↓ (False)
Display Final Error Message

Error Categorization System

Get last archive error
    ↓
Switch on String: Error Message
    ↓ (Contains "access denied")
Custom Event: Handle Permission Error
    ↓ (Contains "not found")
Custom Event: Handle Missing File Error
    ↓ (Contains "corrupt")
Custom Event: Handle Corruption Error
    ↓ (Default)
Custom Event: Handle Generic Error

Debugging Tips

Error Investigation

  • Check file paths: Verify all paths are correct and accessible
  • Test permissions: Ensure sufficient read/write permissions
  • Monitor resources: Check available disk space and memory
  • Validate inputs: Confirm all input parameters are valid
  • Test edge cases: Try with empty files, large files, special characters

Common Solutions

  • Permission errors: Run as administrator or adjust file permissions
  • Path errors: Use absolute paths and validate existence
  • Space errors: Free up disk space or use alternative location
  • Memory errors: Close other applications or process smaller batches
  • Corruption errors: Verify archive integrity or use different source

Error Logging and Analytics

Structured Error Logging

struct FArchiveErrorInfo
{
    FString Operation;
    FString ErrorMessage;
    FDateTime Timestamp;
    FString FilePath;
    int32 FileCount;
    int64 DataSize;
};

class UArchiveErrorLogger
{
public:
    static void LogError(const FArchiveErrorInfo& ErrorInfo)
    {
        UE_LOG(LogTemp, Error, TEXT("Archive Error: %s | %s | %s"), 
               *ErrorInfo.Operation, 
               *ErrorInfo.ErrorMessage, 
               *ErrorInfo.Timestamp.ToString());
        
        // Optional: Send to analytics service
        SendToAnalytics(ErrorInfo);
    }
};

The Get last archive error function is essential for building robust, user-friendly applications that handle archive operations gracefully. By implementing proper error handling using this function, you can provide better user experiences and easier debugging when issues occur.

Table of Contents