Skip to content

Error type is missing the source property #141

@AndyOGo

Description

@AndyOGo

RSocket error frames are turning into standard Error() objects, and expanded by a source property.
The Error type does not reflect that fact.

Expected Behavior

All errors should be of a custom error type, if applicable.
And type guards could be useful too.

interface RSocketErrorSource {
  code: number;
  explanation: string;
  message: string;
}

interface RSocketError extends Error {
  source: RSocketErrorSource;
}
function isRSocketError(value: any): value is RSocketError {
  return Object.prototype.toString.call(value) === "[object Error]" && isRSocketErrorSource(value.source);
}

function isRSocketErrorSource(value: any): value is RSocketErrorSource {
  return source && source?.code && source?.explanation && source?.message;
}

Actual Behavior

Insufficient Error type is used, this prohibits auto-completion and discovery.

Affected code examples:

  • export function createErrorFromFrame(frame: ErrorFrame): Error {
    const {code, message} = frame;
    const explanation = getErrorCodeExplanation(code);
    const error = new Error(
    sprintf(
    'RSocket error %s (%s): %s. See error `source` property for details.',
    toHex(code),
    explanation,
    message,
    ),
    );
    (error: any).source = {
    code,
    explanation,
    message,
    };
    return error;
    }

Possible Solution

Please see expected above, it shows an interface.

Your Environment

  • RSocket version(s) used: 0.0.25

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSuggests, requests, or implements a feature or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions