mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
Move PosixError into puter-js-common
The in-progress git client also needs to use this. puter-js-common uses commonjs modules, so it had to be adjusted for that.
This commit is contained in:
parent
1f6a2093fb
commit
e43b21387c
@ -20,7 +20,7 @@ import fs from 'fs';
|
||||
import path_ from 'path';
|
||||
|
||||
import modeString from 'fs-mode-to-string';
|
||||
import { ErrorCodes, PosixError } from '../PosixError.js';
|
||||
import { ErrorCodes, PosixError } from '@heyputer/puter-js-common/src/PosixError.js';
|
||||
|
||||
function convertNodeError(e) {
|
||||
switch (e.code) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ErrorCodes, PosixError } from '../PosixError.js';
|
||||
import { ErrorCodes, PosixError } from '@heyputer/puter-js-common/src/PosixError.js';
|
||||
|
||||
function convertPuterError(e) {
|
||||
// Handle Puter SDK errors
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ErrorCodes, ErrorMetadata, errorFromIntegerCode } from '../../platform/PosixError.js';
|
||||
import { ErrorCodes, ErrorMetadata, errorFromIntegerCode } from '@heyputer/puter-js-common/src/PosixError.js';
|
||||
import { Exit } from './coreutil_lib/exit.js';
|
||||
|
||||
const maxErrorNameLength = Object.keys(ErrorCodes)
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
import { Exit } from './coreutil_lib/exit.js';
|
||||
import { resolveRelativePath } from '../../util/path.js';
|
||||
import { ErrorCodes } from '../../platform/PosixError.js';
|
||||
import { ErrorCodes } from '@heyputer/puter-js-common/src/PosixError.js';
|
||||
|
||||
export default {
|
||||
name: 'touch',
|
||||
|
@ -19,7 +19,7 @@
|
||||
import assert from 'assert';
|
||||
import { MakeTestContext } from './harness.js'
|
||||
import builtins from '../../src/puter-shell/coreutils/__exports__.js';
|
||||
import { ErrorCodes, ErrorMetadata } from '../../src/platform/PosixError.js';
|
||||
import { ErrorCodes, ErrorMetadata } from '@heyputer/puter-js-common/src/PosixError.js';
|
||||
|
||||
export const runErrnoTests = () => {
|
||||
describe('errno', function () {
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Puter Technologies Inc.
|
||||
*
|
||||
* This file is part of Phoenix Shell.
|
||||
* This file is part of Puter.
|
||||
*
|
||||
* Phoenix Shell is free software: you can redistribute it and/or modify
|
||||
* Puter is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const ErrorCodes = {
|
||||
const ErrorCodes = {
|
||||
EACCES: Symbol.for('EACCES'),
|
||||
EADDRINUSE: Symbol.for('EADDRINUSE'),
|
||||
ECONNREFUSED: Symbol.for('ECONNREFUSED'),
|
||||
@ -37,7 +37,7 @@ export const ErrorCodes = {
|
||||
};
|
||||
|
||||
// Codes taken from `errno` on Linux.
|
||||
export const ErrorMetadata = new Map([
|
||||
const ErrorMetadata = new Map([
|
||||
[ErrorCodes.EPERM, { code: 1, description: 'Operation not permitted' }],
|
||||
[ErrorCodes.ENOENT, { code: 2, description: 'File or directory not found' }],
|
||||
[ErrorCodes.EIO, { code: 5, description: 'IO error' }],
|
||||
@ -57,7 +57,7 @@ export const ErrorMetadata = new Map([
|
||||
[ErrorCodes.ECONNREFUSED, { code: 111, description: 'Connection refused' }],
|
||||
]);
|
||||
|
||||
export const errorFromIntegerCode = (code) => {
|
||||
const errorFromIntegerCode = (code) => {
|
||||
for (const [errorCode, metadata] of ErrorMetadata) {
|
||||
if (metadata.code === code) {
|
||||
return errorCode;
|
||||
@ -66,7 +66,7 @@ export const errorFromIntegerCode = (code) => {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export class PosixError extends Error {
|
||||
class PosixError extends Error {
|
||||
// posixErrorCode can be either a string, or one of the ErrorCodes above.
|
||||
// If message is undefined, a default message will be used.
|
||||
constructor(posixErrorCode, message) {
|
||||
@ -141,3 +141,10 @@ export class PosixError extends Error {
|
||||
return new PosixError(ErrorCodes.ETIMEDOUT, message);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ErrorCodes,
|
||||
ErrorMetadata,
|
||||
errorFromIntegerCode,
|
||||
PosixError,
|
||||
}
|
Loading…
Reference in New Issue
Block a user