Skip to content

Commit

Permalink
NC | CLI | Health trimmed output fix
Browse files Browse the repository at this point in the history
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
  • Loading branch information
romayalon committed Jun 9, 2024
1 parent 2ff4086 commit d57da2f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
18 changes: 13 additions & 5 deletions src/cmd/manage_nsfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ async function main(argv = minimist(process.argv.slice(2))) {
const user_input = user_input_from_file || argv;
config_root = argv.config_root ? String(argv.config_root) : config.NSFS_NC_CONF_DIR;
if (!config_root) throw_cli_error(ManageCLIError.MissingConfigDirPath);
if (argv.config_root) config.NSFS_NC_CONF_DIR = String(argv.config_root);
if (argv.config_root) {
config.NSFS_NC_CONF_DIR = String(argv.config_root);
config.load_nsfs_nc_config();
config.reload_nsfs_nc_config();
}

accounts_dir_path = path.join(config_root, accounts_dir_name);
access_keys_dir_path = path.join(config_root, access_keys_dir_name);
Expand All @@ -102,10 +106,13 @@ async function main(argv = minimist(process.argv.slice(2))) {
} catch (err) {
dbg.log1('NSFS Manage command: exit on error', err.stack || err);
const manage_err = ((err instanceof ManageCLIError) && err) ||
new ManageCLIError(ManageCLIError.FS_ERRORS_TO_MANAGE[err.code] ||
new ManageCLIError({
...(ManageCLIError.FS_ERRORS_TO_MANAGE[err.code] ||
ManageCLIError.RPC_ERROR_TO_MANAGE[err.rpc_code] ||
ManageCLIError.InternalError);
throw_cli_error(manage_err, err.stack || err);
ManageCLIError.InternalError), cause: err });
process.stdout.write(manage_err.to_string() + '\n', () => {
process.exit(1);
});
}
}

Expand Down Expand Up @@ -256,7 +263,8 @@ async function delete_bucket(data, force) {
if (object_entries.length === 0 || force) {
await native_fs_utils.folder_delete(bucket_temp_dir_path, fs_context_fs_backend, true);
await native_fs_utils.delete_config_file(fs_context_config_root_backend, buckets_dir_path, bucket_config_path);
write_stdout_response(ManageCLIResponse.BucketDeleted, '', {bucket: data.name});
write_stdout_response(ManageCLIResponse.BucketDeleted, '', { bucket: data.name });
return;
}
throw_cli_error(ManageCLIError.BucketDeleteForbiddenHasObjects, data.name);
} catch (err) {
Expand Down
12 changes: 8 additions & 4 deletions src/manage_nsfs/manage_nsfs_cli_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEve
* code?: string,
* message: string,
* http_code: number,
* detail: string,
* cause?: Error
* }} ManageCLIErrorSpec
*/

Expand All @@ -16,18 +18,20 @@ class ManageCLIError extends Error {
/**
* @param {ManageCLIErrorSpec} error_spec
*/
constructor({ code, message, http_code }) {
super(message); // sets this.message
constructor({ code, message, http_code, detail, cause }) {
super(message, { cause });
this.code = code;
this.http_code = http_code;
this.detail = detail;
}

to_string(detail) {
to_string() {
const json = {
error: {
code: this.code,
message: this.message,
detail: detail
detail: this.detail,
cause: this.cause?.stack || this.cause?.message
}
};
return JSON.stringify(json, null, 2);
Expand Down
14 changes: 7 additions & 7 deletions src/manage_nsfs/manage_nsfs_cli_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ const NSFS_CLI_SUCCESS_EVENT_MAP = require('../manage_nsfs/manage_nsfs_cli_respo
const { BOOLEAN_STRING_VALUES } = require('../manage_nsfs/manage_nsfs_constants');
const NoobaaEvent = require('../manage_nsfs/manage_nsfs_events_utils').NoobaaEvent;

function throw_cli_error(error_code, detail, event_arg) {
const error_event = NSFS_CLI_ERROR_EVENT_MAP[error_code.code];
function throw_cli_error(error, detail, event_arg) {
const error_event = NSFS_CLI_ERROR_EVENT_MAP[error.code];
if (error_event) {
new NoobaaEvent(error_event).create_event(undefined, event_arg, undefined);
}
const err = new ManageCLIError(error_code).to_string(detail);
process.stdout.write(err + '\n');
process.exit(1);
const err = new ManageCLIError({ ...error, detail });
throw err;
}

function write_stdout_response(response_code, detail, event_arg) {
Expand All @@ -28,8 +27,9 @@ function write_stdout_response(response_code, detail, event_arg) {
new NoobaaEvent(response_event).create_event(undefined, event_arg, undefined);
}
const res = new ManageCLIResponse(response_code).to_string(detail);
process.stdout.write(res + '\n');
process.exit(0);
process.stdout.write(res + '\n', () => {
process.exit(0);
});
}

function get_config_file_path(config_type_path, file_name) {
Expand Down

0 comments on commit d57da2f

Please sign in to comment.