Skip to content

Commit e798576

Browse files
committed
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.
1 parent cc45a08 commit e798576

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

packages/phoenix/src/platform/node/filesystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import fs from 'fs';
2020
import path_ from 'path';
2121

2222
import modeString from 'fs-mode-to-string';
23-
import { ErrorCodes, PosixError } from '../PosixError.js';
23+
import { ErrorCodes, PosixError } from '@heyputer/puter-js-common/src/PosixError.js';
2424

2525
function convertNodeError(e) {
2626
switch (e.code) {

packages/phoenix/src/platform/puter/filesystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19-
import { ErrorCodes, PosixError } from '../PosixError.js';
19+
import { ErrorCodes, PosixError } from '@heyputer/puter-js-common/src/PosixError.js';
2020

2121
function convertPuterError(e) {
2222
// Handle Puter SDK errors

packages/phoenix/src/puter-shell/coreutils/errno.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19-
import { ErrorCodes, ErrorMetadata, errorFromIntegerCode } from '../../platform/PosixError.js';
19+
import { ErrorCodes, ErrorMetadata, errorFromIntegerCode } from '@heyputer/puter-js-common/src/PosixError.js';
2020
import { Exit } from './coreutil_lib/exit.js';
2121

2222
const maxErrorNameLength = Object.keys(ErrorCodes)

packages/phoenix/src/puter-shell/coreutils/touch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
import { Exit } from './coreutil_lib/exit.js';
2020
import { resolveRelativePath } from '../../util/path.js';
21-
import { ErrorCodes } from '../../platform/PosixError.js';
21+
import { ErrorCodes } from '@heyputer/puter-js-common/src/PosixError.js';
2222

2323
export default {
2424
name: 'touch',

packages/phoenix/test/coreutils/errno.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import assert from 'assert';
2020
import { MakeTestContext } from './harness.js'
2121
import builtins from '../../src/puter-shell/coreutils/__exports__.js';
22-
import { ErrorCodes, ErrorMetadata } from '../../src/platform/PosixError.js';
22+
import { ErrorCodes, ErrorMetadata } from '@heyputer/puter-js-common/src/PosixError.js';
2323

2424
export const runErrnoTests = () => {
2525
describe('errno', function () {

packages/phoenix/src/platform/PosixError.js renamed to packages/puter-js-common/src/PosixError.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
* Copyright (C) 2024 Puter Technologies Inc.
33
*
4-
* This file is part of Phoenix Shell.
4+
* This file is part of Puter.
55
*
6-
* Phoenix Shell is free software: you can redistribute it and/or modify
6+
* Puter is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published
88
* by the Free Software Foundation, either version 3 of the License, or
99
* (at your option) any later version.
@@ -16,7 +16,7 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19-
export const ErrorCodes = {
19+
const ErrorCodes = {
2020
EACCES: Symbol.for('EACCES'),
2121
EADDRINUSE: Symbol.for('EADDRINUSE'),
2222
ECONNREFUSED: Symbol.for('ECONNREFUSED'),
@@ -37,7 +37,7 @@ export const ErrorCodes = {
3737
};
3838

3939
// Codes taken from `errno` on Linux.
40-
export const ErrorMetadata = new Map([
40+
const ErrorMetadata = new Map([
4141
[ErrorCodes.EPERM, { code: 1, description: 'Operation not permitted' }],
4242
[ErrorCodes.ENOENT, { code: 2, description: 'File or directory not found' }],
4343
[ErrorCodes.EIO, { code: 5, description: 'IO error' }],
@@ -57,7 +57,7 @@ export const ErrorMetadata = new Map([
5757
[ErrorCodes.ECONNREFUSED, { code: 111, description: 'Connection refused' }],
5858
]);
5959

60-
export const errorFromIntegerCode = (code) => {
60+
const errorFromIntegerCode = (code) => {
6161
for (const [errorCode, metadata] of ErrorMetadata) {
6262
if (metadata.code === code) {
6363
return errorCode;
@@ -66,7 +66,7 @@ export const errorFromIntegerCode = (code) => {
6666
return undefined;
6767
};
6868

69-
export class PosixError extends Error {
69+
class PosixError extends Error {
7070
// posixErrorCode can be either a string, or one of the ErrorCodes above.
7171
// If message is undefined, a default message will be used.
7272
constructor(posixErrorCode, message) {
@@ -141,3 +141,10 @@ export class PosixError extends Error {
141141
return new PosixError(ErrorCodes.ETIMEDOUT, message);
142142
}
143143
}
144+
145+
module.exports = {
146+
ErrorCodes,
147+
ErrorMetadata,
148+
errorFromIntegerCode,
149+
PosixError,
150+
}

0 commit comments

Comments
 (0)