Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mcp

Model Context Protocol server for Pudu language documentation and compiler tools

0.1.1Apache-2.01

InstallClose

RpcError.pudu

Pudu54 lines1.9 KB

GitHub ↗
1/** @Errors.RpcError.Module — protocol refusals and their wire form */2module PuduLangMcp.Errors.RpcError34import Std.Json as Json5import PuduLangMcp.Constants.Protocol as Protocol67/** @Errors.RpcError.ProtocolError — every protocol-level refusal */8export type ProtocolError9  = ParseError(Str)10  | InvalidRequest(Str)11  | MethodNotFound(Str)12  | InvalidParams(Str)13  | ResourceNotFound(Str)14  | UnsupportedVersion(Str)15  | Internal(Str)1617/// The JSON-RPC error code for a refusal.18export fn code(problem: &ProtocolError) -> Int {19  match problem {20    case ParseError(_) => Protocol.PARSE_ERROR21    case InvalidRequest(_) => Protocol.INVALID_REQUEST22    case MethodNotFound(_) => Protocol.METHOD_NOT_FOUND23    case InvalidParams(_) => Protocol.INVALID_PARAMS24    case ResourceNotFound(_) => Protocol.INVALID_PARAMS25    case UnsupportedVersion(_) => Protocol.UNSUPPORTED_PROTOCOL_VERSION26    case Internal(_) => Protocol.INTERNAL_ERROR27  }28}2930/// The error message for a refusal, with its detail.31export fn message(problem: &ProtocolError) -> Str {32  match problem {33    case ParseError(detail) => "Parse error: " + detail34    case InvalidRequest(detail) => "Invalid request: " + detail35    case MethodNotFound(method) => "Method not found: " + method36    case InvalidParams(detail) => "Invalid params: " + detail37    case ResourceNotFound(_) => "Resource not found"38    case UnsupportedVersion(_) => "Unsupported protocol version"39    case Internal(detail) => "Internal error: " + detail40  }41}4243/// Structured error data, for the refusals that carry it.44export fn data(problem: &ProtocolError) -> Option[Json.Json] {45  match problem {46    case ResourceNotFound(uri) => Some(Json.object(&[("uri", Json.Text(uri))]))47    case UnsupportedVersion(requested) => Some(Json.object(&[48          ("supported", Json.list(&Protocol.supportedVersions().map(|v: Str| Json.Text(v)))),49          ("requested", Json.Text(requested))50        ]))51    case _ => None52  }53}54