{"record":{"id":"63b19f22478e3072","repo":"argoproj/argo-workflows","slug":"os-create-s-w","errorCode":null,"errorMessage":"os create %s: %w","messagePattern":"os create (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/artifacts/gcs/gcs.go","lineNumber":176,"sourceCode":"\trelObjPath := strings.TrimPrefix(objName, objPrefix)\n\tlocalPath := filepath.Join(path, relObjPath)\n\tobjectDir, _ := filepath.Split(localPath)\n\tif objectDir != \"\" {\n\t\tif err := os.MkdirAll(objectDir, 0o700); err != nil {\n\t\t\treturn fmt.Errorf(\"mkdir %s: %w\", objectDir, err)\n\t\t}\n\t}\n\trc, err := client.Bucket(bucket).Object(objName).NewReader(ctx)\n\tif err != nil {\n\t\tif errors.Is(err, storage.ErrObjectNotExist) {\n\t\t\treturn argoerrors.New(argoerrors.CodeNotFound, err.Error())\n\t\t}\n\t\treturn fmt.Errorf(\"new bucket reader: %w\", err)\n\t}\n\tdefer rc.Close()\n\tout, err := os.Create(localPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"os create %s: %w\", localPath, err)\n\t}\n\tdefer func() {\n\t\tif closeErr := out.Close(); closeErr != nil {\n\t\t\tlogger := logging.RequireLoggerFromContext(ctx)\n\t\t\tlogger.WithField(\"path\", localPath).WithError(closeErr).Error(ctx, \"Error closing file\")\n\t\t}\n\t}()\n\t_, err = io.Copy(out, rc)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"io copy: %w\", err)\n\t}\n\treturn nil\n}\n\n// list all the object names of the prefix in the bucket\nfunc listByPrefix(ctx context.Context, client *storage.Client, bucket, prefix, delim string) ([]string, error) {\n\tctx, cancel := context.WithTimeout(ctx, time.Second*30)\n\tdefer cancel()","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/artifacts/gcs/gcs.go#L158-L194","documentation":"After successfully opening the GCS reader, downloadObject creates the local file with os.Create(localPath). This error wraps an os.Create failure, i.e. the local artifact file could not be opened for writing even though its directory exists.","triggerScenarios":"os.Create fails on localPath: path exists as a directory, permission denied for the container user, path too long (ENAMETOOLONG), or filesystem/I/O error on the output volume.","commonSituations":"GCS object whose name ends with '/' produced a directory at localPath; running as non-root (runAsUser) without write access to /tmp or the output volume; artifact path exceeding filesystem name limits.","solutions":["Ensure the local path doesn't clash with an existing directory (check the GCS key names for trailing-slash objects)","Grant the container user write access: securityContext.runAsUser + fsGroup matching the volume, or chmod the mount","Shorten the artifact path or the GCS key names","Check volume/filesystem health"],"exampleFix":"// before\nsecurityContext: {runAsUser: 1000}  # volume owned by root, mode 755\n// after\nsecurityContext: {runAsUser: 1000, fsGroup: 1000}  # or add initContainer chmod on emptyDir","handlingStrategy":"validation","validationCode":"import \"os\"\nfunc canCreate(path string) error {\n\tif fi, err := os.Lstat(path); err == nil && fi.IsDir() {\n\t\treturn fmt.Errorf(\"%s is a directory\", path)\n\t}\n\tf, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0o600)\n\tif err != nil { return err }\n\treturn f.Close()\n}","typeGuard":null,"tryCatchPattern":"if err := download(ctx, art, path); err != nil {\n\tvar pe *fs.PathError\n\tif errors.As(err, &pe) && os.IsPermission(pe) {\n\t\t// fix runAsUser/fsGroup or chmod the volume before retry\n\t}\n\treturn err\n}","preventionTips":["Match securityContext.runAsUser/fsGroup with volume ownership","Avoid GCS keys ending in '/' that materialize as local directories","Keep artifact paths short and under writable mounts like /tmp"],"tags":["filesystem","gcs","permissions","artifacts"],"backgroundTag":"file-open-permission-denied","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}