{"record":{"id":"85b7526b69734196","repo":"larksuite/cli","slug":"inline-image-q-w","errorCode":null,"errorMessage":"inline image %q: %w","messagePattern":"inline image %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/patch.go","lineNumber":625,"sourceCode":"\t\tMediaType:   \"multipart/mixed\",\n\t\tMediaParams: map[string]string{\"boundary\": boundary},\n\t\tDirty:       true,\n\t\tHeaders: []Header{\n\t\t\t{Name: \"Content-Type\", Value: mime.FormatMediaType(\"multipart/mixed\", map[string]string{\"boundary\": boundary})},\n\t\t},\n\t\tChildren: []*Part{original, attachment},\n\t}\n\treturn nil\n}\n\n// loadAndAttachInline reads a local image file, validates its format,\n// creates a MIME inline part, and attaches it to the snapshot's\n// multipart/related container. If container is non-nil it is reused;\n// otherwise the container is resolved from the snapshot.\nfunc loadAndAttachInline(dctx *DraftCtx, snapshot *DraftSnapshot, path, cid, fileName string, container *Part) (*Part, error) {\n\tinfo, err := dctx.FIO.Stat(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"inline image %q: %w\", path, err)\n\t}\n\tif err := checkSnapshotAttachmentLimit(snapshot, info.Size(), nil); err != nil {\n\t\treturn nil, err\n\t}\n\tf, err := dctx.FIO.Open(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"inline image %q: %w\", path, err)\n\t}\n\tdefer f.Close()\n\tcontent, err := io.ReadAll(f)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"inline image %q: %w\", path, err)\n\t}\n\tname := fileName\n\tif strings.TrimSpace(name) == \"\" {\n\t\tname = filepath.Base(path)\n\t}\n\tdetectedCT, err := filecheck.CheckInlineImageFormat(name, content)","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/patch.go#L607-L643","documentation":"loadAndAttachInline failed at the first step: Stat on the local image path via the draft FileIO returned an error, wrapped as \"inline image %q: %w\". The file does not exist, is inaccessible, or the path is invalid in the current execution context (path resolution/validation happens before this point). The original Stat error is preserved as the cause.","triggerScenarios":"Calling addInline or resolveLocalImgSrc with a path that does not exist, has a typo, is outside the allowed workspace, or the runtime lacks read permission — FIO.Stat(path) fails.","commonSituations":"Relative path used where an absolute path is expected; file deleted between HTML authoring and the inline-attach step; sandbox/remote execution where the CLI's FileIO cannot see the developer's local file; wrong working directory.","solutions":["Verify the image path exists and is readable from the CLI's execution context (use absolute paths).","Resolve the path through the runtime's path validation (runtime.ValidatePath) so workspace-relative paths resolve correctly.","Check file permissions and that the file lives inside the allowed workspace/execution scope.","If running remotely or sandboxed, copy the image into the workspace the FileIO can access first."],"exampleFix":"// before\naddInline(ctx, snapshot, \"./assets/logo.png\", \"logo\", \"\")\n// after: ensure absolute, existing path\npath := \"/work/project/assets/logo.png\" // verified to exist\naddInline(ctx, snapshot, path, \"logo\", \"\")","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil || info.IsDir() {\n\treturn fmt.Errorf(\"inline image path unusable: %w\", err)\n}","typeGuard":"func fileReadable(path string) bool {\n\tinfo, err := os.Stat(path)\n\treturn err == nil && !info.IsDir()\n}","tryCatchPattern":"part, err := loadAndAttachInline(dctx, snapshot, path, cid, name, nil)\nif err != nil {\n\tvar perr *fs.PathError\n\tif errors.As(err, &perr) && errors.Is(perr, fs.ErrNotExist) {\n\t\t// fix path / copy file into workspace\n\t}\n\treturn err\n}","preventionTips":["Use absolute, verified paths for inline images.","Ensure the image lives inside the workspace/scope the CLI's FileIO can access.","Stat the file before invoking addInline."],"tags":["email","file-io","inline-image","filesystem"],"backgroundTag":"file-not-found","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}