Skip to content

Commit

Permalink
fix: Logger issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anadian committed Sep 11, 2022
1 parent 0527818 commit 8473d4d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
92 changes: 46 additions & 46 deletions source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,44 +111,44 @@ function getDocumentationStringFromSourceString_Test(){
} catch(error){
if( error.code === 'ERR_INVALID_ARG_TYPE' ){
arg_test = true;
} elsejs\c0{
} else/* c8 ignore start */{
arg_test = error;
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: `Failure: invalid arg test: received an unexpected error: ${error}\n`});
}js\c1
}/* c8 ignore stop */
}
///success test
try {
try{
sample_input_path = Path.resolve( PackageMeta.paths.packageDirectory, 'test/example-source-file.js' );
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `sample_input_path: ${sample_input_path}`});
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`Path.resolve threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
try{
sample_input_string = FileSystem.readFileSync( sample_input_path, { encoding: 'utf8', flag: 'r' } );
//sample_input_string = readFileSyncBinaryMode( sample_input_path, 'utf8' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`FileSystem.readFileSync threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
try{
expected_output_path = Path.resolve( PackageMeta.paths.packageDirectory, 'test/example-source-file-output.txt' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`Path.resolve threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
try{
expected_output_string = FileSystem.readFileSync( expected_output_path, { encoding: 'utf8', flag: 'r' } );
//expected_output_string = readFileSyncBinaryMode( expected_output_path, 'utf8' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`FileSystem.readFileSync threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
actual_output_string = ExtractDocumentationComments.getDocumentationStringFromSourceString( sample_input_string );
if( actual_output_string === expected_output_string ){
success_test = true;
} elsejs\c0{
} else/* c8 ignore start */{
success_test = new Error(`success test failed: actual output: '${actual_output_string}' didn't match expected output '${expected_output_string}'`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: success_test.message});
//Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: `Leven difference ${Leven(actual_output_string, expected_output_string)}`});
Expand All @@ -157,14 +157,14 @@ function getDocumentationStringFromSourceString_Test(){
} catch(error){
success_test = error;
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: `Failure: success test caught an unexpected error: ${error}\n`});
}js\c1
}/* c8 ignore stop */
if( (arg_test === true) && (success_test === true) ){
_return = true;
} elsejs\c0{
} else/* c8 ignore start */{
_return = false;
return_error = new Error(`Test failed: invalid arg test: '${arg_test}' success test: '${success_test}'\n`);
throw return_error;
}js\c1
}/* c8 ignore stop */
//Return
return _return;
}
Expand Down Expand Up @@ -212,10 +212,10 @@ function getDocumentationStringFromSourceBuffer_Test(){
if( error.code === 'ERR_INVALID_ARG_TYPE' ){
arg_test = true;
//console.log('arg_test passed.');
} elsejs\c0{
} else/* c8 ignore start */{
arg_test = new Error(`Failure: ${test_name}: received an unexpected error: '${error}'`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: arg_test.message});
}js\c1
}/* c8 ignore stop */
}
test_name = 'null buffer test';
try{
Expand All @@ -227,58 +227,58 @@ function getDocumentationStringFromSourceBuffer_Test(){
if( error.code === 'ERR_INVALID_RETURN_VALUE' ){
null_buffer_test = true;
//console.log('null_buffer_test passed.');
} elsejs\c0{
} else/* c8 ignore start */{
null_buffer_test = new Error(`Failure: ${test_name}: received an unexpected error: ${error}`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: null_buffer_test.message});
}js\c1
}/* c8 ignore stop */
}
test_name = 'success test';
try {
try{
sample_input_path = Path.resolve( PackageMeta.paths.packageDirectory, 'test/example-source-file.js' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`Path.resolve threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
try{
sample_input_buffer = FileSystem.readFileSync( sample_input_path );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`FileSystem.readFileSync threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
try{
expected_output_path = Path.resolve( PackageMeta.paths.packageDirectory, 'test/example-source-file-output.txt' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`Path.resolve threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
try{
expected_output_string = FileSystem.readFileSync( expected_output_path, 'utf8' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`FileSystem.readFileSync threw an error: ${error}`);
throw return_error;
}js\c1
}/* c8 ignore stop */
//input = new Buffer.from(FileSystem.readFileSync(path.resolve(__dirname, '../testFiles/testInput.js')), 'utf8')
actual_output_string = ExtractDocumentationComments.getDocumentationStringFromSourceBuffer( sample_input_buffer );
if( actual_output_string === expected_output_string ){
success_test = true;
//console.log('success_test passed');
} elsejs\c0{
} else/* c8 ignore start */{
success_test = new Error(`Failure: ${test_name}: actual output '${actual_output_string}' didn't match expected output '${expected_output_string}'`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: success_test.message});
}
} catch(error){
success_test = new Error(`Failure: ${test_name}: caught unexpected exception: ${error}`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: success_test.message});
}js\c1
}/* c8 ignore stop */
//Return
if( (arg_test === true) && (null_buffer_test === true) && (success_test === true) ){
_return = true;
} elsejs\c0{
} else/* c8 ignore start */{
return_error = new Error(`Test failed: invalid arg test: '${arg_test}' null buffer test: '${null_buffer_test}' success test: '${success_test}'`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
throw return_error;
}js\c1
}/* c8 ignore stop */
return _return;
}
/**
Expand Down Expand Up @@ -338,7 +338,7 @@ async function main_Async( options = {} ){
FileSystem.writeFileSync( output_path, output_string, 'utf8' );
report_file_object.success = true;
report.files.push( report_file_object );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
report_file_object.error = new Error(`FileSystem.writeFileSync threw an error: ${error}`);
report.files.push( report_file_object );
}
Expand All @@ -363,7 +363,7 @@ async function main_Async( options = {} ){
} else{
return_error = new Error('"options.output" (`--output`) must be specified when using multi-file mode.');
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}js\c1
}/* c8 ignore stop */
}
} //Single-file mode
if( multi_file_mode === false ){
Expand All @@ -373,17 +373,17 @@ async function main_Async( options = {} ){
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'info', message: 'Reading input from STDIN.'});
try{
input_string = await GetStream( process.stdin, 'utf8' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`GetStream threw an error: ${error}`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}js\c1
}/* c8 ignore stop */
} else if( options.input != null ){
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'info', message: 'Reading input from a file.'});
if( typeof(options.input[0]) === 'string' ){
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'debug', message: `options.input: '${options.input[0]}'`});
try{
input_string = FileSystem.readFileSync( options.input[0], 'utf8' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`FileSystem.readFileSync threw an error: ${error}`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}
Expand All @@ -394,50 +394,50 @@ async function main_Async( options = {} ){
} else{
return_error = new Error('No input options specified.');
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}js\c1
}/* c8 ignore stop */
}
///Transform
if( return_error === null ){
if( input_string !== '' && typeof(input_string) === 'string' ){
try{
output_string = ExtractDocumentationComments.getDocumentationStringFromSourceString( input_string, options );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`getDocumentationStringFromSourceString threw an error: ${error}`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}
} else{
return_error = new Error('input_string is either null or not a string.');
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}js\c1
}/* c8 ignore stop */
}
///Output
if( return_error === null ){
if( output_string !== '' && typeof(output_string) === 'string' ){
if( options.output != null && typeof(output_string) === 'string' ){
try{
FileSystem.writeFileSync( options.output, output_string, 'utf8' );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
return_error = new Error(`FileSystem.writeFileSync threw an error: ${error}`);
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}js\c1
}/* c8 ignore stop */
} else{
if( options.stdout !== true ){
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'warn', message: 'No output options specified; defaulting to STDOUT.'});
}
console.log(output_string);
}
} elsejs\c0{
} else/* c8 ignore start */{
return_error = new Error('"output_string" is either null or not a string.');
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}js\c1
}/* c8 ignore stop */
}
}

//Return
if( return_error !== null )js\c0{
if( return_error !== null )/* c8 ignore start */{
process.exitCode = 1;
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'crit', message: return_error.message});
}js\c1
}/* c8 ignore stop */
}
/**
### main_Async_Test (private)
Expand All @@ -464,10 +464,10 @@ async function main_Async_Test(){
getDocumentationStringFromSourceString_Test();
console.log('buffer');
getDocumentationStringFromSourceBuffer_Test();
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'crit', message: `Test failed with error: '${error}'`});
process.exitCode = 4;
}js\c1
}/* c8 ignore stop */
//Return
return _return;
}
Expand Down
12 changes: 6 additions & 6 deletions source/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
//import Assert from 'assert';
import OperatingSystem from 'node:os';
//##External
import nullLogger from 'application-log-winston-interface';
import * as ApplicationLogWinstonInterface from 'application-log-winston-interface';

//#Constants
const FILENAME = 'extract-documentation-comments.js';
Expand All @@ -47,7 +47,7 @@ const PROCESS_NAME = 'extract-documentation-comments';
//##Errors

//#Global Variables
var Logger = nullLogger;
var Logger = ApplicationLogWinstonInterface.nullLogger;
/**
## Functions
*/
Expand All @@ -70,7 +70,7 @@ Status:
| --- | --- |
| 0.0.0 | Introduced |
*/
function setLogger( logger )js\c0{
function setLogger( logger )/* c8 ignore start */{
var return_error = null;
//const FUNCTION_NAME = 'setLogger';
//Variables
Expand All @@ -93,7 +93,7 @@ function setLogger( logger )js\c0{
//Function
Logger = logger;
//Return
}js\c1
}/* c8 ignore stop */

/**
### getDocumentationStringFromSourceString
Expand Down Expand Up @@ -199,10 +199,10 @@ function getDocumentationStringFromSourceBuffer( source_buffer , options = {} ){
if( buffer_string !== '' ){
try{
_return = getDocumentationStringFromSourceString( buffer_string, options );
} catch(error)js\c0{
} catch(error)/* c8 ignore start */{
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: `Received and throwing error: ${error}`});
throw error;
}js\c1
}/* c8 ignore stop */
} else{
return_error = new Error(`'source_buffer.toString()' returned an empty string or a non-string: ${buffer_string}`);
return_error.code = 'ERR_INVALID_RETURN_VALUE';
Expand Down

0 comments on commit 8473d4d

Please sign in to comment.