Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions sdks/ts/packages/golem-ts-sdk/src/internal/agentError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,22 @@ export function invalidType(error: string): AgentError {
};
}

export function isAgentError(error: any): error is AgentError {
export function isAgentError(error: unknown): error is AgentError {
if (typeof error !== 'object' || error === null) {
return false;
}
const e = error as Record<string, unknown>;
return (
error.tag !== undefined &&
error.val !== undefined &&
((error.tag === 'invalid-input' && typeof error.val === 'string') ||
(error.tag === 'invalid-method' && typeof error.val === 'string') ||
(error.tag === 'invalid-type' && typeof error.val === 'string') ||
(error.tag === 'invalid-agent-id' && typeof error.val === 'string') ||
(error.tag === 'custom-error' &&
typeof error.val === 'object' &&
error.val.value !== undefined &&
error.val.typ !== undefined))
e.tag !== undefined &&
e.val !== undefined &&
((e.tag === 'invalid-input' && typeof e.val === 'string') ||
(e.tag === 'invalid-method' && typeof e.val === 'string') ||
(e.tag === 'invalid-type' && typeof e.val === 'string') ||
(e.tag === 'invalid-agent-id' && typeof e.val === 'string') ||
(e.tag === 'custom-error' &&
typeof e.val === 'object' &&
e.val !== null &&
(e.val as Record<string, unknown>).value !== undefined &&
(e.val as Record<string, unknown>).typ !== undefined))
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function serializeDefaultTsValue(
if (typeof tsValue === 'bigint' || typeof tsValue === 'number') {
return Either.right({
kind: 'u64',
value: tsValue as any,
value: typeof tsValue === 'bigint' ? tsValue : BigInt(tsValue as number),
});
} else {
return Either.left(typeMismatchInSerialize(tsValue, 'bigint'));
Expand Down Expand Up @@ -395,7 +395,7 @@ export function serializeDefaultTsValue(
}

if (!('tag' in tsValue)) {
return Either.left(missingObjectKey(tsValue, 'tag'));
return Either.left(missingObjectKey('tag', tsValue));
}

switch (analysedType.resultType.tag) {
Expand Down Expand Up @@ -599,7 +599,7 @@ export function serializeTextReferenceTsValue(tsValue: any): Value {
}

export function serializeTsValueToBinaryReference(tsValue: any): BinaryReference {
if (typeof tsValue === 'object') {
if (typeof tsValue === 'object' && tsValue !== null) {
const keys = Object.keys(tsValue);

if (!keys.includes('tag')) {
Expand Down Expand Up @@ -662,7 +662,7 @@ export function serializeTsValueToBinaryReference(tsValue: any): BinaryReference
}

export function serializeTsValueToTextReference(value: any): TextReference {
if (typeof value === 'object') {
if (typeof value === 'object' && value !== null) {
const keys = Object.keys(value);

if (!keys.includes('tag')) {
Expand Down Expand Up @@ -1163,7 +1163,7 @@ function matchesArray(
}

function handleObjectMatch(value: any, props: NameTypePair[]): boolean {
if (typeof value !== 'object' && value !== 'interface') {
if (typeof value !== 'object' || value === null) {
return false;
}

Expand Down
Loading