meilleur gestion des erreur dans sheebr et dans chibrax/kernel.js
This commit is contained in:
@@ -25,13 +25,12 @@ function finit_module(path, params = "", flags = 0) {
|
|||||||
const fileDescriptor = open(path, modes.O_RDONLY)
|
const fileDescriptor = open(path, modes.O_RDONLY)
|
||||||
const result = syscall(SYSCALL_FINIT_MODULE, fileDescriptor, params, flags)
|
const result = syscall(SYSCALL_FINIT_MODULE, fileDescriptor, params, flags)
|
||||||
if(result > 0) {
|
if(result > 0) {
|
||||||
//parse linux error
|
throw new Error(errno[result])
|
||||||
console.log(errno[result])
|
|
||||||
} else {
|
} else {
|
||||||
if(result == -1) {
|
if(result == -1) {
|
||||||
console.log('non number or string argument recived')
|
throw new Error('non number or string argument recived')
|
||||||
}else if(result == -2) {
|
}else if(result == -2) {
|
||||||
console.log('unsuported argument length (1-5)')
|
throw new Error('unsuported argument length (1-5)')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,8 +51,7 @@ function modprobe(modulename) {
|
|||||||
if(fs.existsSync(path.join('/lib/modules', name, 'kernel', modulename))) {
|
if(fs.existsSync(path.join('/lib/modules', name, 'kernel', modulename))) {
|
||||||
finit_module(path.join('/lib/modules', name, 'kernel', modulename))
|
finit_module(path.join('/lib/modules', name, 'kernel', modulename))
|
||||||
} else {
|
} else {
|
||||||
console.log("file not found " + path.join('/lib/modules', name, 'kernel', modulename))
|
throw new Error("file not found " + path.join('/lib/modules', name, 'kernel', modulename))
|
||||||
//throw "file not found"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,21 @@ const { getline } = require('../lib/sheebr/utils')
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
let environment = require('../lib/sheebr/environment')
|
let environment = require('../lib/sheebr/environment')
|
||||||
let aliases = require("../lib/sheebr/aliases")
|
let aliases = require("../lib/sheebr/aliases")
|
||||||
let execSync = require('child_process').execSync
|
let { spawn } = require('child_process')
|
||||||
|
|
||||||
|
//utiliser ce code au lieuxc de execSync permet d'afficher le stdout au fur et a mesure ce qui fait qu'on a les logs quand une application throw une erreur
|
||||||
|
async function spawnAndWait(cmd, option) {
|
||||||
|
const child = spawn(cmd, option)
|
||||||
|
|
||||||
|
child.stdout.pipe(process.stdout)
|
||||||
|
process.stdin.pipe(child.stdin)
|
||||||
|
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
child.on('exit', () => {
|
||||||
|
res()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let current_dir = process.cwd()
|
let current_dir = process.cwd()
|
||||||
@@ -16,11 +30,11 @@ async function start(){
|
|||||||
const input = await getline("sheebr> ");
|
const input = await getline("sheebr> ");
|
||||||
if(input == "exit") break;
|
if(input == "exit") break;
|
||||||
if(input == "") continue;
|
if(input == "") continue;
|
||||||
else evaluate(input);
|
else await evaluate(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function evaluate(input){
|
async function evaluate(input){
|
||||||
let lexer = new Lexer(input)
|
let lexer = new Lexer(input)
|
||||||
let args = lexer.scanTokens()
|
let args = lexer.scanTokens()
|
||||||
args = evaluateAliases(args)
|
args = evaluateAliases(args)
|
||||||
@@ -49,14 +63,14 @@ function evaluate(input){
|
|||||||
console.clear();
|
console.clear();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
evaluateProgram(args)
|
await evaluateProgram(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function evaluateProgram(args){
|
async function evaluateProgram(args){
|
||||||
|
|
||||||
let found = false;
|
let found = false;
|
||||||
for(let path of environment.path){
|
for(let path of environment.path){
|
||||||
@@ -65,9 +79,7 @@ function evaluateProgram(args){
|
|||||||
if(files.includes(`${args[0]}.js`)){
|
if(files.includes(`${args[0]}.js`)){
|
||||||
found = true;
|
found = true;
|
||||||
try {
|
try {
|
||||||
//@ts-expect-error
|
await spawnAndWait(`${environment.node} ${path + '/' + args[0]}.js ${args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')}`, {cwd: current_dir, env: environment, shell: true});
|
||||||
const script = execSync(`${environment.node} ${path + '/' + args[0]}.js ${args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')}`, {cwd: current_dir, env: environment, shell: true});
|
|
||||||
process.stdout.write(script)
|
|
||||||
tobreak = true;
|
tobreak = true;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log("Program crashed")
|
console.log("Program crashed")
|
||||||
|
|||||||
Reference in New Issue
Block a user