Summary
HostPipeline returns the response with body: parsedBody as T, a runtime cast. When the server's actual body type doesn't match the caller's declared T, this throws an unhandled TypeError instead of returning a handled response/error.
File: packages/dart/morph_core/lib/src/http/host_pipeline.dart:223
Root cause
parsedBody is typed Object? (L184) and JSON responses are decoded into Map/List (L192, jsonDecode).
- The success path returns
body: parsedBody as T (L223).
- If a consumer declares
MorphResponse<String> but the endpoint returns content-type: application/json (parsed to a Map), or declares MorphResponse<Map> but the body is a bare JSON array or a non-JSON String, the cast throws a raw TypeError.
Why this is a Dart-specific regression
In the TypeScript source parsed as T is a compile-time-only assertion and never throws at runtime. The Dart as T is checked at runtime, so a response the TS SDK handled fine now crashes.
Repro
A 200 endpoint that a consumer typed as MorphResponse<String> returns content-type: application/json with {"x":1} → crash with an opaque cast error rather than a MorphResponse/MorphHttpError.
Proposed fix
Guard the cast (e.g. is T check → surface a typed decode error or a safe fallback), or return a dynamic/Object? body and let callers coerce, or emit a MorphHttpError/decode error on type mismatch instead of an unguarded cast.
Severity
High — crashes on an otherwise-valid server response.
Found in a local review of PR #37 (head fdbce85).
Summary
HostPipelinereturns the response withbody: parsedBody as T, a runtime cast. When the server's actual body type doesn't match the caller's declaredT, this throws an unhandledTypeErrorinstead of returning a handled response/error.File:
packages/dart/morph_core/lib/src/http/host_pipeline.dart:223Root cause
parsedBodyis typedObject?(L184) and JSON responses are decoded intoMap/List(L192,jsonDecode).body: parsedBody as T(L223).MorphResponse<String>but the endpoint returnscontent-type: application/json(parsed to aMap), or declaresMorphResponse<Map>but the body is a bare JSON array or a non-JSONString, the cast throws a rawTypeError.Why this is a Dart-specific regression
In the TypeScript source
parsed as Tis a compile-time-only assertion and never throws at runtime. The Dartas Tis checked at runtime, so a response the TS SDK handled fine now crashes.Repro
A
200endpoint that a consumer typed asMorphResponse<String>returnscontent-type: application/jsonwith{"x":1}→ crash with an opaque cast error rather than aMorphResponse/MorphHttpError.Proposed fix
Guard the cast (e.g.
is Tcheck → surface a typed decode error or a safe fallback), or return adynamic/Object?body and let callers coerce, or emit aMorphHttpError/decode error on type mismatch instead of an unguarded cast.Severity
High — crashes on an otherwise-valid server response.
Found in a local review of PR #37 (head
fdbce85).