Skip to content

Commit

Permalink
reflect coderabbitai feedback: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Intizar-T committed May 25, 2024
1 parent 71a6625 commit 13136f4
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
const fs = require('fs')
const fs = require('node:fs')

// Get the key from the terminal argument
const hash = process.argv[2]
const MAPPING_PATH = 'scripts/sol-error-mappings/errorMappings.json'

function handleLogging({ exitCode, logMessage, errorMessage }) {
if (logMessage) {
console.log(logMessage)
}
if (errorMessage) {
console.error(errorMessage)
}
if (exitCode) {
process.exit(exitCode)
}
}

function main() {
if (!hash) {
console.error('hash not provided')
process.exit(1)
handleLogging({ exitCode: 1, errorMessage: 'hash not provided' })
}

try {
const data = fs.readFileSync(MAPPING_PATH, 'utf8')
const obj = JSON.parse(data)
const value = obj[hash]
if (!value) {
console.error('----hash not found----')
handleLogging({ exitCode: 1, errorMessage: 'hash not found' })
} else {
console.log(value)
handleLogging({ logMessage: value })
}
} catch (error) {
console.error(error)
process.exit(1)
handleLogging({ exitCode: 1, errorMessage: error.message })
}
}

Expand Down

0 comments on commit 13136f4

Please sign in to comment.