Skip to content

Commit

Permalink
JavaScript exception mapping fixes (#2562)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Jul 25, 2024
1 parent a6674e6 commit 8a8a93e
Show file tree
Hide file tree
Showing 47 changed files with 1,640 additions and 1,618 deletions.
2 changes: 1 addition & 1 deletion cpp/src/slice2js/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ Slice::Gen::ImportVisitor::writeImports(const UnitPtr& p)

if (_seenUserException)
{
jsIceImports.insert("Exception");
jsIceImports.insert("UserException");
jsIceImports.insert("TypeRegistry");
}

Expand Down
4 changes: 2 additions & 2 deletions js/src/Ice/AsyncResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { AsyncResultBase } from "./AsyncResultBase.js";
import { OutputStream } from "./Stream.js";
import { Protocol } from "./Protocol.js";
import { UserException } from "./Exception.js";
import { InvocationCanceledException } from "./LocalException.js";
import { UserException } from "./UserException.js";
import { InvocationCanceledException } from "./LocalExceptions.js";
import { Debug } from "./Debug.js";

export class AsyncResult extends AsyncResultBase {
Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/Communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import { CommunicatorDestroyedException } from "./LocalException.js";
import { CommunicatorDestroyedException } from "./LocalExceptions.js";
import { generateUUID } from "./UUID.js";
import { identityToString } from "./IdentityUtil.js";
import { Promise } from "./Promise.js";
Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/ConnectRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

import { AsyncStatus } from "./AsyncStatus.js";
import { LocalException } from "./Exception.js";
import { LocalException } from "./LocalException.js";
import { RetryException } from "./RetryException.js";
import { Debug } from "./Debug.js";

Expand Down
4 changes: 2 additions & 2 deletions js/src/Ice/ConnectionI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import { LocalException } from "./Exception.js";
import { LocalException } from "./LocalException.js";
import {
IllegalMessageSizeException,
ObjectAdapterDeactivatedException,
Expand All @@ -21,7 +21,7 @@ import {
ConnectionNotValidatedException,
UnknownMessageException,
UnknownException,
} from "./LocalException.js";
} from "./LocalExceptions.js";

import { ConnectionClose } from "./Connection.js";

Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/DefaultsAndOverrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { FormatType } from "./FormatType.js";
import { EndpointSelectionType } from "./EndpointSelectionType.js";
import { Protocol, stringToEncodingVersion, encodingVersionToString } from "./Protocol.js";
import { EndpointSelectionTypeParseException } from "./LocalException.js";
import { EndpointSelectionTypeParseException } from "./LocalExceptions.js";
import { TcpTransceiver } from "./TcpTransceiver.js";

export class DefaultsAndOverrides {
Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/EndpointFactoryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import { EndpointParseException } from "./LocalException.js";
import { EndpointParseException } from "./LocalExceptions.js";
import { StringUtil } from "./StringUtil.js";
import { OpaqueEndpointI } from "./OpaqueEndpoint.js";
import { Protocol } from "./Protocol.js";
Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/ExUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import { UnexpectedObjectException, MemoryLimitException } from "./LocalException.js";
import { UnexpectedObjectException, MemoryLimitException } from "./LocalExceptions.js";

export function throwUOE(expectedType, v) {
const type = v.ice_id();
Expand Down
16 changes: 0 additions & 16 deletions js/src/Ice/Exception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,5 @@ declare module "ice" {

ice_cause: string | Error;
}

/**
* Base class for all Ice run-time exceptions.
*/
abstract class LocalException extends Exception {}

/**
* Base class for all Ice user exceptions.
*/
abstract class UserException extends Exception {
/**
* Obtains the Slice type ID of this exception.
* @return The fully-scoped type ID.
*/
static ice_staticId(): string;
}
}
}
94 changes: 1 addition & 93 deletions js/src/Ice/Exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const toString = function (key, object, objectTable, ident) {
//
// Ice.Exception
//
class Exception extends Error {
export class Exception extends Error {
constructor(cause) {
super();
if (cause) {
Expand Down Expand Up @@ -86,95 +86,3 @@ class Exception extends Error {
}
}
}

//
// Ice.LocalException
//
class LocalException extends Exception {
constructor(cause) {
super(cause);
Exception.captureStackTrace(this);
}

static get _id() {
return "::Ice::LocalException";
}
}

//
// Ice.UserException
//
class UserException extends Exception {
constructor(cause) {
super(cause);
Exception.captureStackTrace(this);
}

static get _id() {
return "::Ice::UserException";
}

_write(os) {
os.startException();
writeImpl(this, os, this._mostDerivedType());
os.endException();
}

_read(is) {
is.startException();
readImpl(this, is, this._mostDerivedType());
is.endException();
}

_usesClasses() {
return false;
}

_mostDerivedType() {
return UserException;
}
}

//
// Private methods
//

const writeImpl = function (obj, os, type) {
//
// The writeImpl method is a recursive method that goes down the
// class hierarchy to marshal each slice of the class using the
// generated _writeMemberImpl method.
//

if (type === undefined || type === UserException) {
return; // Don't marshal anything for Ice.UserException
}

os.startSlice(type._id, -1, type._parent === UserException);
if (type.prototype.hasOwnProperty("_writeMemberImpl")) {
type.prototype._writeMemberImpl.call(obj, os);
}
os.endSlice();
writeImpl(obj, os, type._parent);
};

const readImpl = function (obj, is, type) {
//
// The readImpl method is a recursive method that goes down the
// class hierarchy to marshal each slice of the class using the
// generated _readMemberImpl method.
//

if (type === undefined || type === UserException) {
return; // Don't marshal anything for UserException
}

is.startSlice();
if (type.prototype.hasOwnProperty("_readMemberImpl")) {
type.prototype._readMemberImpl.call(obj, is);
}
is.endSlice();
readImpl(obj, is, type._parent);
};

export { Exception, LocalException, UserException };
2 changes: 1 addition & 1 deletion js/src/Ice/IPEndpointI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

import { Address } from "./Address.js";
import { EndpointParseException } from "./LocalException.js";
import { EndpointParseException } from "./LocalExceptions.js";
import { HashUtil } from "./HashUtil.js";
import { StringUtil } from "./StringUtil.js";
import { EndpointI } from "./EndpointI.js";
Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/IdentityUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import { IdentityParseException } from "./LocalException.js";
import { IdentityParseException } from "./LocalExceptions.js";
import { StringUtil } from "./StringUtil.js";
import { Ice as Ice_Identity } from "./Identity.js";
import { ToStringMode } from "./ToStringMode.js";
Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/ImplicitContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Ice as Ice_Context } from "./Context.js";
const { Context, ContextHelper } = Ice_Context;

import { InitializationException } from "./LocalException.js";
import { InitializationException } from "./LocalExceptions.js";

//
// The base class for all ImplicitContext implementations
Expand Down
5 changes: 3 additions & 2 deletions js/src/Ice/IncomingAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { Ice as Ice_Identity } from "./Identity.js";
const { Identity } = Ice_Identity;
import { identityToString } from "./IdentityUtil.js";
import { FormatType } from "./FormatType.js";
import { LocalException, UserException } from "./Exception.js";
import { LocalException } from "./LocalException.js";
import { UserException } from "./UserException.js";
import {
FacetNotExistException,
MarshalException,
Expand All @@ -21,7 +22,7 @@ import {
UnknownException,
UnknownLocalException,
UnknownUserException,
} from "./LocalException.js";
} from "./LocalExceptions.js";

import { Protocol } from "./Protocol.js";
import { OutputStream } from "./Stream.js";
Expand Down
2 changes: 1 addition & 1 deletion js/src/Ice/Initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { Communicator } from "./Communicator.js";
import { Protocol } from "./Protocol.js";
import { InitializationException } from "./LocalException.js";
import { InitializationException } from "./LocalExceptions.js";
import { Properties } from "./Properties.js";

export class InitializationData {
Expand Down
4 changes: 2 additions & 2 deletions js/src/Ice/InstanceExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { RouterManager } from "./RouterManager.js";
import { Timer } from "./Timer.js";
import { TraceLevels } from "./TraceLevels.js";
import { ValueFactoryManager } from "./ValueFactoryManager.js";
import { LocalException } from "./Exception.js";
import { CommunicatorDestroyedException, InitializationException } from "./LocalException.js";
import { LocalException } from "./LocalException.js";
import { CommunicatorDestroyedException, InitializationException } from "./LocalExceptions.js";
import { getProcessLogger } from "./ProcessLogger.js";
import { ToStringMode } from "./ToStringMode.js";
import { ProtocolInstance } from "./ProtocolInstance.js";
Expand Down
Loading

0 comments on commit 8a8a93e

Please sign in to comment.