{"record":{"id":"799439aed9a57857","repo":"n8n-io/n8n","slug":"failed-to-write-label-tolowercase-filepath-799439","errorCode":null,"errorMessage":"Failed to write ${label.toLowerCase()} \"${filePath}\": ${formatErrorForLog(error)}","messagePattern":"Failed to write (.+?) \"(.+?)\": (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/src/workspace/workspace-files.ts","lineNumber":162,"sourceCode":"\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t} catch (fallbackError) {\n\t\t\t\tif (isAbortError(fallbackError)) throw fallbackError;\n\t\t\t\t// Preserve whichever path carries quota metadata so callers can\n\t\t\t\t// classify the combined failure correctly.\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to write ${label.toLowerCase()} \"${filePath}\": ${formatErrorForLog(error)}; command fallback failed: ${formatErrorForLog(fallbackError)}`,\n\t\t\t\t\t{ cause: selectWriteFailureCause(error, fallbackError) },\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\ttry {\n\t\tawait writeFileViaSandbox(workspace, filePath, content, options);\n\t} catch (error) {\n\t\tif (isAbortError(error)) throw error;\n\t\tthrow new Error(\n\t\t\t`Failed to write ${label.toLowerCase()} \"${filePath}\": ${formatErrorForLog(error)}`,\n\t\t\t{ cause: error },\n\t\t);\n\t}\n}\n\nexport async function writeWorkspaceFileMap(\n\tworkspace: WorkspaceFileTarget,\n\tfiles: Map<string, string>,\n\toptions?: WorkspaceFileOptions,\n): Promise<void> {\n\tawait Promise.all(\n\t\tArray.from(files, async ([filePath, content]) => {\n\t\t\tawait writeWorkspaceFile(workspace, filePath, content, options);\n\t\t}),\n\t);\n}\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/src/workspace/workspace-files.ts#L144-L180","documentation":"Thrown by writeWorkspaceFile in the sandbox-only branch (no workspace.filesystem defined): writeFileViaSandbox failed and it was not an abort error. The original error is attached as `cause`. This path is taken for command-only sandbox providers like Daytona that expose no filesystem API — only shell command execution.","triggerScenarios":"Calling writeWorkspaceFile where workspace.filesystem is undefined (workspace.sandbox only), and writeFileViaSandbox throws a non-abort error after its own retry loop. This includes non-transient command failures (exit code != 0, base64 decode failure, mkdir failure) that the retry loop does not retry.","commonSituations":"Sandbox command write exited non-zero because the target path is read-only or permission denied; base64 decode failed because the chunked printf was truncated mid-transfer (E2BIG on a huge file); the workspace ran out of disk mid-write; the sandbox shell is non-POSIX and lacks base64/printf.","solutions":["Read err.cause for the underlying command stderr — it carries the real reason (permission, disk, decode failure).","If the file is large and E2BIG is suspected, split the content into smaller writes or reduce BASE64_WRITE_CHUNK_SIZE.","Verify the sandbox shell supports base64 -d and printf (the command fallback assumes a POSIX shell).","Check workspace permissions on the target directory."],"exampleFix":"// before\nawait writeWorkspaceFile(workspace, filePath, content, opts);\n\n// after — surface the underlying command error\ntry {\n  await writeWorkspaceFile(workspace, filePath, content, opts);\n} catch (err) {\n  const detail = err.cause instanceof Error ? err.cause.message : String(err.cause);\n  throw new Error(`Workspace write to ${filePath} failed: ${detail}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isSandboxWriteError(error: unknown): boolean {\n  return error instanceof Error && /Failed to write/.test(error.message);\n}","tryCatchPattern":"try {\n  await writeWorkspaceFile(workspace, filePath, content, opts);\n} catch (err) {\n  const detail = err.cause instanceof Error ? err.cause.message : String(err.cause);\n  logger.error('sandbox write failed', { path: filePath, detail });\n  throw err;\n}","preventionTips":["Inspect err.cause for the underlying command stderr to find the real reason.","Confirm the sandbox shell is POSIX (supports base64 -d, printf) before relying on the command path.","For very large files, write in chunks to avoid E2BIG on the base64 printf."],"tags":["sandbox","filesystem","write","instance-ai","command-fallback"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}