snes-disassembler
Version:
A Super Nintendo (SNES) ROM disassembler for 65816 assembly
56 lines • 2.11 kB
JavaScript
;
/**
* Result Types for Better Error Handling
*
* Implements Result pattern for better error management
* and eliminates need for try-catch everywhere.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DisassemblerError = exports.DisassemblerErrorType = exports.flatMap = exports.map = exports.isFailure = exports.isSuccess = exports.Err = exports.Ok = void 0;
// Factory functions
const Ok = (data) => ({ success: true, data });
exports.Ok = Ok;
const Err = (error) => ({ success: false, error });
exports.Err = Err;
// Utility functions
const isSuccess = (result) => result.success;
exports.isSuccess = isSuccess;
const isFailure = (result) => !result.success;
exports.isFailure = isFailure;
// Chain operations
const map = (result, fn) => {
if ((0, exports.isSuccess)(result)) {
return (0, exports.Ok)(fn(result.data));
}
return result;
};
exports.map = map;
const flatMap = (result, fn) => {
if ((0, exports.isSuccess)(result)) {
return fn(result.data);
}
return result;
};
exports.flatMap = flatMap;
// Error types for the disassembler
var DisassemblerErrorType;
(function (DisassemblerErrorType) {
DisassemblerErrorType["ROM_NOT_FOUND"] = "ROM_NOT_FOUND";
DisassemblerErrorType["INVALID_ROM_FORMAT"] = "INVALID_ROM_FORMAT";
DisassemblerErrorType["INVALID_ADDRESS_RANGE"] = "INVALID_ADDRESS_RANGE";
DisassemblerErrorType["DECODER_ERROR"] = "DECODER_ERROR";
DisassemblerErrorType["SYMBOL_LOAD_ERROR"] = "SYMBOL_LOAD_ERROR";
DisassemblerErrorType["OUTPUT_ERROR"] = "OUTPUT_ERROR";
DisassemblerErrorType["ANALYSIS_ERROR"] = "ANALYSIS_ERROR";
DisassemblerErrorType["BRR_DECODE_ERROR"] = "BRR_DECODE_ERROR";
})(DisassemblerErrorType || (exports.DisassemblerErrorType = DisassemblerErrorType = {}));
class DisassemblerError extends Error {
constructor(type, message, context) {
super(message);
this.type = type;
this.context = context;
this.name = 'DisassemblerError';
}
}
exports.DisassemblerError = DisassemblerError;
//# sourceMappingURL=result-types.js.map