Skip to content

[BUG] Design import/export silently succeeds on nonexistent/invalid paths #109

@ranveerd11

Description

@ranveerd11

Problem

design import and design export commands succeed silently even when given paths that don't exist or are not writable.

Steps to Reproduce

# Import from nonexistent file - should fail
ainative-code design import --file /nonexistent/file.json
# Exit code: 0 (success) - WRONG!

# Export to non-writable path - should fail  
ainative-code design export --file /root/cannot/write/here.json
# Exit code: 0 (success) - WRONG!

Expected Behavior

ainative-code design import --file /nonexistent/file.json
# Error: file not found: /nonexistent/file.json

ainative-code design export --file /root/cannot/write/here.json
# Error: permission denied: cannot write to /root/cannot/write/here.json

Actual Behavior

Both commands return exit code 0 without any error message, giving the false impression that the operation succeeded.

Impact

  • Users think their tokens were imported when they weren't
  • Data loss potential if users assume export succeeded
  • Silent failures are hard to debug in scripts

Suggested Fix

Add file existence/permission checks before proceeding:

func validateInputFile(path string) error {
    if _, err := os.Stat(path); os.IsNotExist(err) {
        return fmt.Errorf("file not found: %s", path)
    }
    return nil
}

func validateOutputPath(path string) error {
    dir := filepath.Dir(path)
    if err := os.MkdirAll(dir, 0755); err != nil {
        return fmt.Errorf("cannot create directory: %w", err)
    }
    // Test write permission
    f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
    if err != nil {
        return fmt.Errorf("cannot write to %s: %w", path, err)
    }
    f.Close()
    os.Remove(path)
    return nil
}

Environment

  • Version: v0.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions