{"record":{"id":"7f00e1ca23074a3d","repo":"amir20/dozzle","slug":"error-reading-certificates-w","errorCode":null,"errorMessage":"error reading certificates: %w","messagePattern":"error reading certificates: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/support/cli/agent_test_command.go","lineNumber":19,"sourceCode":"package cli\n\nimport (\n\t\"context\"\n\t\"embed\"\n\t\"fmt\"\n\n\t\"github.com/amir20/dozzle/internal/agent\"\n\t\"github.com/rs/zerolog/log\"\n)\n\ntype AgentTestCmd struct {\n\tAddress string `arg:\"positional\"`\n}\n\nfunc (at *AgentTestCmd) Run(args Args, embeddedCerts embed.FS) error {\n\tcerts, err := ReadCertificates(embeddedCerts, args.CertPath, args.KeyPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading certificates: %w\", err)\n\t}\n\n\tlog.Info().Str(\"endpoint\", args.AgentTest.Address).Msg(\"Connecting to agent\")\n\n\tagent, err := agent.NewClient(args.AgentTest.Address, certs)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error connecting to agent: %w\", err)\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), args.Timeout)\n\tdefer cancel()\n\thost, err := agent.Host(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error fetching host info for agent: %w\", err)\n\t}\n\n\tlog.Info().Str(\"endpoint\", args.AgentTest.Address).Str(\"version\", host.AgentVersion).Str(\"name\", host.Name).Str(\"id\", host.ID).Msg(\"Successfully connected to agent\")\n\n\treturn nil","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/support/cli/agent_test_command.go#L1-L37","documentation":"Returned by AgentTestCmd.Run when ReadCertificates fails while preparing the connectivity test client. The test command needs the same TLS certs as the agent to dial it, so cert load failure aborts the test before any network activity.","triggerScenarios":"--cert-path/--key-path point to missing, unreadable, or malformed files; key does not match the certificate; running a build without embedded certs and no files supplied.","commonSituations":"Testing connectivity to a remote agent from a machine without the shared certs; copied cert files got truncated in transit; wrong paths after moving the install directory.","solutions":["Point --cert-path/--key-path at the same shared cert/key pair the agent uses.","Regenerate certs with `make generate` and copy both files to the testing machine.","Validate files: `openssl x509 -in cert.pem -noout && openssl rsa -in key.pem -check`.","Fix file read permissions for the current user.","Use a build with embedded certs instead of a bare source checkout."],"exampleFix":"// before\n./dozzle agent-test 10.0.0.5:7007  # no certs on this machine\n// after\nscp server:/shared/{cert.pem,key.pem} /etc/dozzle/\n./dozzle agent-test --cert-path /etc/dozzle/cert.pem --key-path /etc/dozzle/key.pem 10.0.0.5:7007","handlingStrategy":"validation","validationCode":"[ -r \"$CERT\" ] && [ -r \"$KEY\" ] || { echo 'cert files missing/unreadable'; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := agentTestCmd.Run(args, embeddedCerts); err != nil {\n  if strings.Contains(err.Error(), \"error reading certificates\") {\n    log.Fatal().Err(err).Msg(\"supply the agent's shared cert/key via --cert-path/--key-path\")\n  }\n}","preventionTips":["Copy both shared certs to any machine running agent-test","Verify PEM integrity with openssl after transfer","Check permissions on cert files","Use embedded-cert builds where possible"],"tags":["tls","certificates","cli"],"backgroundTag":"file-read-failed","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}