{"record":{"id":"87ed1585d76cee4c","repo":"juanfont/headscale","slug":"writing-q-w","errorCode":null,"errorMessage":"writing %q: %w","messagePattern":"writing %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integration/hsic/hsic.go","lineNumber":627,"sourceCode":"\t\t}\n\t}\n\n\tif hsic.hasTLS() {\n\t\terr = hsic.WriteFile(tlsCertPath, hsic.tlsCert)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"writing TLS certificate to container: %w\", err)\n\t\t}\n\n\t\terr = hsic.WriteFile(tlsKeyPath, hsic.tlsKey)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"writing TLS key to container: %w\", err)\n\t\t}\n\t}\n\n\tfor _, f := range hsic.filesInContainer {\n\t\terr := hsic.WriteFile(f.path, f.contents)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"writing %q: %w\", f.path, err)\n\t\t}\n\t}\n\n\t// Load the database from policy file on repeat until it succeeds,\n\t// this is done as the container sleeps before starting headscale.\n\tif hsic.aclPolicy != nil && hsic.policyMode == types.PolicyModeDB {\n\t\terr := pool.Retry(hsic.reloadDatabasePolicy)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"loading database policy on startup: %w\", err)\n\t\t}\n\t}\n\n\treturn hsic, nil\n}\n\nfunc (t *HeadscaleInContainer) ConnectToNetwork(network *dockertest.Network) error {\n\treturn t.container.ConnectToNetwork(network)\n}","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/integration/hsic/hsic.go#L609-L645","documentation":"Generic per-file error when an option-registered extra file (hsic.filesInContainer, e.g. WithConfigFile/WithFile style options) cannot be written into the container. The %q names the exact path, distinguishing it from the config/TLS/policy writes.","triggerScenarios":"Any test option that adds filesInContainer entries (custom DERP config, extra certs, test fixtures) where WriteFile(path, contents) fails: container not writable, path invalid (missing parent dir), or contents empty where the copy needs input.","commonSituations":"Custom file path pointing to a directory that does not exist in the image; container crashed mid-setup; typo'd absolute path in the option.","solutions":["Look at the %q path in the message and verify its parent directory exists in the container image","Check the container is running (docker ps) and its logs","Fix the path in the test option to an absolute path that exists in the image","Re-run to rule out transient exec failures"],"exampleFix":"// before\nhsic.WithFile(\"derp.yaml\", contents), // path may lack a parent dir\n// after (verify actual option signature; use absolute path)\nhsic.WithFile(\"/etc/headscale/derp.yaml\", contents),","handlingStrategy":"validation","validationCode":"// Before adding a file, ensure the parent dir exists in the image\nfor _, f := range files {\n    if !strings.HasPrefix(f.path, \"/\") { return fmt.Errorf(\"file path %q must be absolute\", f.path) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use absolute paths for all injected files","Only target directories the headscale image already contains","Echo the %q path into test failure output for fast diagnosis"],"tags":["integration-test","docker","file-copy","test-options"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}