langgenius/dify · error · BaseError

Unknown

Unknown

Error message

--file ${parsed.varname}: upload of ${parsed.path} failed: ${(err as Error).message}

What it means

Thrown by `resolveFileInputs` (file-flags.ts:102) wrapping any failure from the `upload` callback (a `FileUploadClient.upload` call) in a `BaseError` with code `unknown` (exit 1). The original error is preserved via `cause`. The message echoes the varname, the local path, and the underlying error message — so the root cause (network, 4xx, file not found, size limit) appears inline.

Source

Thrown at cli/src/commands/run/app/file-flags.ts:102

  const result: Record<string, unknown> = {}

  for (const raw of rawFlags) {
    const parsed = parseFileFlag(raw)

    if (parsed.kind === 'remote') {
      const filename = new URL(parsed.url).pathname.split('/').pop() ?? ''
      result[parsed.varname] = {
        type: difyFileType(filename),
        transfer_method: 'remote_url',
        url: parsed.url,
      }
    } else {
      const filename = basename(parsed.path)
      let uploaded: { id: string }
      try {
        uploaded = await upload(appId, parsed.path)
      } catch (err) {
        throw new BaseError({
          code: ErrorCode.Unknown,
          message: `--file ${parsed.varname}: upload of ${parsed.path} failed: ${(err as Error).message}`,
          cause: err,
        })
      }
      result[parsed.varname] = {
        type: difyFileType(filename),
        transfer_method: 'local_file',
        upload_file_id: uploaded.id,
      }
    }
  }

  return result
}

View on GitHub (pinned to ef8544b173)

Solutions

  1. Inspect the embedded `(err as Error).message` — it carries the real HTTP status / fs error.
  2. Verify the path is readable: `ls -l <path>` from the same cwd the CLI runs in.
  3. Re-auth if the underlying error is 401/403: `difyctl auth login`.
  4. Retry on transient network/5xx; shrink the file if the server reports a size limit.
Defensive patterns

Strategy: try-catch

Validate before calling

import { access } from 'node:fs/promises'
// Pre-check readability before upload
async function ensureReadable(path: string): Promise<void> {
  await access(path, fs.constants.R_OK)
}

Try / catch

try {
  await resolveFileInputs(appId, files, upload)
} catch (err) {
  if (err instanceof BaseError && err.code === ErrorCode.Unknown &&
      /^--file .*: upload of .* failed:/.test(err.message)) {
    // inspect err.cause for the real HTTP/fs error and branch on it
  }
  throw err
}

Prevention

When it happens

Trigger: Local file (`key=@path`) upload to Dify's file-upload endpoint fails: file does not exist, is unreadable, exceeds the server size limit, the workspace/app rejects it (403/422), the token lacks upload scope, or the network drops mid-upload.

Common situations: Path typo / wrong cwd; file permissions; expired or unscoped API token; Dify server enforces a max upload size; transient network blip; the app was deleted between parse and upload.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/68a6bfc86537fc06. Report an issue: GitHub.