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 result = syscall(SYSCALL_FINIT_MODULE, fileDescriptor, params, flags)
|
||||
if(result > 0) {
|
||||
//parse linux error
|
||||
console.log(errno[result])
|
||||
throw new Error(errno[result])
|
||||
} else {
|
||||
if(result == -1) {
|
||||
console.log('non number or string argument recived')
|
||||
throw new Error('non number or string argument recived')
|
||||
}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))) {
|
||||
finit_module(path.join('/lib/modules', name, 'kernel', modulename))
|
||||
} else {
|
||||
console.log("file not found " + path.join('/lib/modules', name, 'kernel', modulename))
|
||||
//throw "file not found"
|
||||
throw new Error("file not found " + path.join('/lib/modules', name, 'kernel', modulename))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,21 @@ const { getline } = require('../lib/sheebr/utils')
|
||||
const fs = require('fs')
|
||||
let environment = require('../lib/sheebr/environment')
|
||||
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()
|
||||
@@ -16,11 +30,11 @@ async function start(){
|
||||
const input = await getline("sheebr> ");
|
||||
if(input == "exit") break;
|
||||
if(input == "") continue;
|
||||
else evaluate(input);
|
||||
else await evaluate(input);
|
||||
}
|
||||
}
|
||||
|
||||
function evaluate(input){
|
||||
async function evaluate(input){
|
||||
let lexer = new Lexer(input)
|
||||
let args = lexer.scanTokens()
|
||||
args = evaluateAliases(args)
|
||||
@@ -49,14 +63,14 @@ function evaluate(input){
|
||||
console.clear();
|
||||
break;
|
||||
default:
|
||||
evaluateProgram(args)
|
||||
await evaluateProgram(args)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function evaluateProgram(args){
|
||||
async function evaluateProgram(args){
|
||||
|
||||
let found = false;
|
||||
for(let path of environment.path){
|
||||
@@ -65,9 +79,7 @@ function evaluateProgram(args){
|
||||
if(files.includes(`${args[0]}.js`)){
|
||||
found = true;
|
||||
try {
|
||||
//@ts-expect-error
|
||||
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)
|
||||
await spawnAndWait(`${environment.node} ${path + '/' + args[0]}.js ${args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ')}`, {cwd: current_dir, env: environment, shell: true});
|
||||
tobreak = true;
|
||||
} catch(e) {
|
||||
console.log("Program crashed")
|
||||
|
||||
Reference in New Issue
Block a user