{"record":{"id":"3d65c16aed00b6dc","repo":"gleam-lang/gleam","slug":"error-setting-ctrl-c-handler","errorCode":null,"errorMessage":"Error setting Ctrl-C handler","messagePattern":"Error setting Ctrl-C handler","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-cli/src/run.rs","lineNumber":39,"sourceCode":"\n#[derive(Debug, Clone, Copy)]\npub enum Which {\n    Src,\n    Test,\n    Dev,\n}\n\npub fn command(\n    paths: &ProjectPaths,\n    arguments: Vec<String>,\n    target: Option<Target>,\n    runtime: Option<Runtime>,\n    module: Option<String>,\n    which: Which,\n    no_print_progress: bool,\n) -> Result<(), Error> {\n    // Don't exit on ctrl+c as it is used by child erlang shell\n    ctrlc::set_handler(move || {}).expect(\"Error setting Ctrl-C handler\");\n    let command = setup(\n        paths,\n        arguments,\n        target,\n        runtime,\n        module,\n        which,\n        no_print_progress,\n    )?;\n    let status = ProjectIO::new().exec(command)?;\n    std::process::exit(status);\n}\n\npub fn setup(\n    paths: &ProjectPaths,\n    arguments: Vec<String>,\n    target: Option<Target>,\n    runtime: Option<Runtime>,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/gleam-lang/gleam/blob/3e3c5ddc08f0e23b3f7e5331506920b884007b5f/compiler-cli/src/run.rs#L21-L57","documentation":"'gleam run' installs a no-op SIGINT handler with ctrlc::set_handler(...).expect(\"Error setting Ctrl-C handler\") so Ctrl+C is forwarded to the child Erlang shell instead of killing gleam. The ctrlc crate allows only one handler per process, so set_handler returns an error if a handler is already installed, or when the signal machinery itself cannot be registered (e.g. seccomp blocking sigaction). The expect converts that into an immediate panic before the program starts.","triggerScenarios":"Embedding or wrapping 'gleam run' in a host process that already called ctrlc::set_handler (test harnesses, task runners), or running under a sandbox whose syscall filter blocks signal-handler registration.","commonSituations":"Custom tooling that embeds the gleam CLI in-process; wrappers that install their own Ctrl+C handling; hardened containers with seccomp profiles denying sigaction.","solutions":["Run 'gleam run' as its own process rather than embedded in a host that already owns the Ctrl+C handler","Disable or remove the wrapper's own SIGINT handler before invoking gleam","Relax the sandbox/seccomp profile so signal-handler registration succeeds","Report to gleam if it panics in a normal standalone invocation"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'gleam run' as a standalone process, not embedded in a host that already owns a ctrl-c handler","Remove custom SIGINT handlers from wrappers before delegating to gleam","Allow sigaction/signal syscalls in seccomp profiles for containers running gleam"],"tags":["signals","ctrl-c","erlang-shell","rust","panic","gleam","run"],"backgroundTag":"signal-handler-registration-failed","analyzedSha":"3e3c5ddc08f0e23b3f7e5331506920b884007b5f","analyzedAt":"2026-08-20T06:21:11.390Z","contentChangedAt":"2026-08-20T06:21:11.390Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}