Repository navigation
[sentry:7860727273] The event's stack ends in Node's mkdirSync called from src/daemon/spawn.ts. spawnDaemon prepares <data>/atc/logs before spawning atc daemon; on this Windows host that m - #112
Open
Ooooze wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The event's stack ends in Node's mkdirSync called from src/daemon/spawn.ts. spawnDaemon prepares /atc/logs before spawning
atc daemon; on this Windows host that mkdir fails with EPERM because the data folder is not writable for the process (ACL, Controlled Folder Access, read-only or elevated-created folder). The environment causes the errno; the code defect is the handling: mkdirSync and openSync(daemonOutLog, 'w') were outside any handling, so a plain Node fs error escaped the command boundary. errorBody() turned it into { code: 'ATC_INTERNAL', message: 'EPERM: operation not permitted, mkdir ...' } and technicalError() replaced the message with the generic boundary text, so the person and Sentry saw only 'cli start: unknown' with failure_reason=unknown while the CLI showed a raw OS string under the meaningless ATC_INTERNAL code. The same function already wraps the child-spawn failure as ATC_DAEMON_START_FAILED and restrict-data.ts wraps data-folder permission failures the same way, so this path uniquely broke the convention and dropped the actionable facts. Fix: new local helper prepareDaemonLog(paths) in src/daemon/spawn.ts runs mkdirSync(logsDir, {recursive:true}) and openSync(daemonOutLog, 'w') in one try/catch and rethrows AtcError('ATC_DAEMON_START_FAILED', 'Could not prepare the server log.', { details: 'log folder , log file : ', hint: 'check that the data folder is writable, or pass another --data-folder' }). spawnDaemon calls it where the two raw calls were; the missing-executable ATC_INTERNAL check, closeSync, child spawn, its ATC_DAEMON_START_FAILED branch and unref are byte-identical. Users now get a named failure with both paths, the OS code and a hint instead of a bare EPERM, and the report carries a known ATC code instead of unknown. Regression test src/daemon/spawn-log-preparation.test.ts reproduces with a file named logs (mkdir EEXIST) and a directory named daemon.out.log (open EISDIR); it failed on base with a raw EEXIST error and passes now. No telemetry, dependency or contract change.Evidence:
Event stack: mkdirSync (node internal) <- src/daemon/spawn.ts:30 <- src/cli/context.ts:112 spawnDaemon <- src/core-link/attach.ts:54,102 <- src/core-link/lifecycle.ts:132,163 <- src/commands/server/lifecycle.ts:207 <- src/main.ts:71 <- src/io.ts:122; facts: component=cli, operation=start, os.name=win32, error_code=EPERM, diagnostic_cause_code=EPERM.
Base code before the patch: line 29
mkdirSync(options.paths.logsDir, { recursive: true })and line 30openSync(options.paths.daemonOutLog, 'w')had no try/catch; only the child-process 'error' branch at the end was wrapped as AtcError('ATC_DAEMON_START_FAILED', 'Could not start the server.').src/errors/errors.ts errorBody(): a non-AtcError Error yields { code: 'ATC_INTERNAL', message: error.message }, which is why the CLI printed a raw 'EPERM: operation not permitted, mkdir ...' with an internal code and no hint.
src/telemetry/failures.ts reportCodeOf()/failureReport(): the message is replaced by the generic boundary text and only ATC_* codes are classified, so the raw fs error produced 'cli start: unknown' with failure_reason=unknown and no path or OS text.
Convention in the same domain: src/daemon/restrict-data.ts throws AtcError('ATC_DAEMON_START_FAILED', 'Could not restrict the data folder to this user.', { details, hint: 'fix the permissions on the data folder and start again' }); src/core-link/attach.ts and src/core-link/lifecycle.ts throw the same code for start failures.
Release equals base: snapshot.base_sha 4d37e3d...d908 and release_shas atc@0.2.20#4d37e3d4a225 are the same commit with an empty release diff, so the inspected code is the release code.
Probe on base (recorded before the patch): 'reports a typed start failure for the log folder and the log file' failed with 'AssertionError: expected Error: EEXIST: file already exists, mkdir ... to match object { code: ATC_DAEMON_START_FAILED }' — an untagged fs error with no details and no ATC_* code.
Check after the patch: src/daemon/spawn-log-preparation.test.ts passed (1/1, fullName 'spawnDaemon when the log file cannot be prepared reports a typed start failure for the log folder and the log file'); both scenarios now reject with code ATC_DAEMON_START_FAILED and details containing the respective path.
No other test pins the old untyped behavior: src/daemon/spawn.test.ts only covers daemonArgs, and a repository search for logsDir finds no assertion on a raw fs error from spawnDaemon; other writers of logsDir (service.test.ts, profile.test.ts, api-port-upgrade.test.ts) only create the folder.
docs/architecture.md mentions ATC_DAEMON_START_FAILED for the wrong-build/start-failure path only, so no documentation restates the removed raw-error behavior and no doc change is required.
Regression tests: src/daemon/spawn-log-preparation.test.ts
Full CI and human review are required.
Report: http://127.0.0.1:8080/tenants/707d0855-80ab-4e1f-a156-f1c4546cbf52/runs/0697ba3c-3e69-4d77-8fb7-7fd83e52df04
Sentry: https://atomic-chat.sentry.io/issues/7860727273/