{"record":{"id":"2c33a480562bc2d3","repo":"apple/pkl","slug":"cliexception-e-message","errorCode":null,"errorMessage":"CliException(e.message!!)","messagePattern":"CliException\\(e\\.message!!\\)","errorType":"exception","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"pkl-cli/src/main/kotlin/org/pkl/cli/CliServer.kt","lineNumber":30,"sourceCode":" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.pkl.cli\n\nimport org.pkl.commons.cli.CliBaseOptions\nimport org.pkl.commons.cli.CliCommand\nimport org.pkl.commons.cli.CliException\nimport org.pkl.core.messaging.ProtocolException\nimport org.pkl.server.Server\n\nclass CliServer(options: CliBaseOptions) : CliCommand(options) {\n  override fun doRun(): Unit =\n    try {\n      val server = Server.stream(System.`in`, System.out)\n      server.use { it.start() }\n    } catch (e: ProtocolException) {\n      throw CliException(e.message!!)\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":33,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-cli/src/main/kotlin/org/pkl/cli/CliServer.kt#L12-L33","documentation":"CliServer.doRun starts an evaluation server over stdin/stdout via Server.stream(). If the server raises a ProtocolException — meaning the client speaking the Pkl server protocol sent malformed or unexpected messages — the server wraps it in a CliException using the protocol error's message. This is how the CLI surfaces protocol-level violations to the host process (e.g. an editor extension driving the server).","triggerScenarios":"Running `pkl server` (Server.stream(System.in, System.out)) when the peer writes bytes that violate the Pkl server protocol: invalid message framing, unknown message types, out-of-order requests, or premature EOF mid-message.","commonSituations":"An editor plugin or tooling client built against a different protocol version drives `pkl server`; a harness pipes garbage or truncated input into stdin; a bug in a custom client sends responses the server never expects.","solutions":["Check that the client driving the server matches the Pkl server protocol version of the installed CLI; upgrade the client or CLI so both sides agree.","Inspect the exception message (it is the raw ProtocolException message) to find which message/step the client got wrong, and fix the client's serialization/framing.","Verify the process piping stdin is not being truncated or closed early (broken pipe from the parent process).","If writing a custom client, validate messages against the protocol spec before writing to stdin."],"exampleFix":"// before: client sends hand-rolled JSON over stdin\nprocess.stdin.write(JSON.stringify({ cmd: \"eval\" }))\n\n// after: use the official protocol client library matching the CLI version\nval client = PklServerClient.connect(process) // emits protocol-compliant messages","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// when driving `pkl server` programmatically\ntry {\n  serverProcess.startAndCommunicate()\n} catch (e: CliException) {\n  // e.message carries the underlying ProtocolException detail;\n  // log it and verify client/CLI protocol version compatibility\n  logger.error(\"Pkl server protocol violation: ${e.message}\")\n}","preventionTips":["Keep the driving client (editor plugin) on the same protocol version as the installed pkl CLI.","Never pipe arbitrary/untrusted bytes into the server's stdin.","Ensure the parent process keeps stdin open until the session completes."],"tags":["cli","server-protocol","ipc"],"backgroundTag":"invalid-argument-format","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}