ibmruntimes / vsam.js

Reading and writing vsam files using NodeJS
Apache License 2.0
10 stars 5 forks source link

vsamObj.close() throws an exception instead of getting callback when the operation failed #11

Closed tangthth closed 2 years ago

tangthth commented 6 years ago

Issue Description:

vsamObj.close() throws an exception instead of getting callback when the close operation failed. But the readme says it supports "a callback function containing an error object if the close operation failed".

Reproduce Steps:

  1. write a nodejs script to trigger an error in vsamObj.close(), for example, close an open vsam data twice, the 2nd close operation should fail
  2. execute the script: <=== it throws an exception instead of getting callback.

Logs:

/u/usra/myscripts:>node test_vsam.js Open the vsam dataset: USRA.NODEJSD.VSAMDS01 /u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts/test_vsam.js:238 vsamObj.close(function(err) { ^

TypeError: VSAM file is not open at TypeError (native) at vsamCloseX (/u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts/test_vsam.js:238:9) at Object. (/u/usra/workdir/nodejs/nodejs.test.vsam_1.0.0/scripts/test_vsam.js:484:1) at Module._compile (module.js:577:32) at Object.Module._extensions..js (module.js:586:10) at Module.load (module.js:494:32) at tryModuleLoad (module.js:453:12) at Function.Module._load (module.js:445:3) at Module.runMain (module.js:611:10) at run (bootstrap_node.js:394:7)

Reference:

vsamObj.close(function(err) { console.log("Closing the vsam dataset the 1st time.") if (err != null) { console.log("Error in closing vsam dataset the 1st time.") console.error("The error is: " + err)
}
console.log("Closed the vsam dataset the 1st time.")
})

vsamObj.close(function(err) { console.log("Closing the vsam dataset the 2nd time.") if (err != null) { console.log("Error in closing vsam dataset the 2nd time.") console.error("The error is: " + err) } console.log("Closed the vsam dataset the 2nd time.") })

console.log("Closed the vsam dataset two times.")

gabylb commented 2 years ago

close() is synchronous. There was a documentation error prior to v3.0.0 and has been corrected. I think the original authors intended to make close() consistent with openSync(), though I don't know why it didn't have the Sync suffix. Please see https://github.com/ibmruntimes/vsam.js#close-a-vsam-dataset:

This function takes no argument. Prior to vsam.js v3.0.0, it was wrongly documented as taking a callback argument. ... This is a synchronous function, and will throw an exception on error (including close() on a dataset that has already been closed).