Fixes the logging of errors when there are no shcema folders

This commit is contained in:
Luis Fernando Molina committed 2021-01-13 19:11:17 +01:00
1 parent f9d71eebea
commit 956c59ef44
5 files changed
+104 -36

No files matched your search

+58 -20
View File
@@ -313,8 +313,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
let project = requestParameters[3]
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Nodes'
checkAllSchmemaDocuments('Node', docsSchema, filePath)
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
if (checkAllSchmemaDocuments('Node', docsSchema, filePath) === true) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
}
} catch (err) {
console.log('[ERROR] httpInterface -> Docs -> Save-Node-Schema -> Method call produced an error.')
@@ -340,8 +343,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
let project = requestParameters[3]
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Concepts'
checkAllSchmemaDocuments('Concept', docsSchema, filePath)
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
if (checkAllSchmemaDocuments('Concept', docsSchema, filePath) === true) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
}
} catch (err) {
console.log('[ERROR] httpInterface -> Docs -> Save-Concept-Schema -> Method call produced an error.')
@@ -367,8 +373,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
let project = requestParameters[3]
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Topics'
checkAllSchmemaDocuments('Topic', docsSchema, filePath)
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
if (checkAllSchmemaDocuments('Topic', docsSchema, filePath) === true) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
}
} catch (err) {
console.log('[ERROR] httpInterface -> Docs -> Save-Topic-Schema -> Method call produced an error.')
@@ -394,8 +403,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
let project = requestParameters[3]
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Tutorials'
checkAllSchmemaDocuments('Tutorial', docsSchema, filePath)
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
if (checkAllSchmemaDocuments('Tutorial', docsSchema, filePath) === true) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
}
} catch (err) {
console.log('[ERROR] httpInterface -> Docs -> Save-Tutorial-Schema -> Method call produced an error.')
@@ -421,8 +433,11 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
let project = requestParameters[3]
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Books'
checkAllSchmemaDocuments('Book', docsSchema, filePath)
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
if (checkAllSchmemaDocuments('Book', docsSchema, filePath) === true) {
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
}
} catch (err) {
console.log('[ERROR] httpInterface -> Docs -> Save-Book-Schema -> Method call produced an error.')
@@ -443,6 +458,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
function checkAllSchmemaDocuments(category, docsSchema, filePath) {
const fs = require('fs')
let noErrorsDuringSaving = true
for (let i = 0; i < docsSchema.length; i++) {
let schemaDocument = docsSchema[i]
@@ -471,6 +487,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
fs.unlinkSync(filePath + '/' + fileName)
console.log('[SUCCESS] ' + filePath + '/' + fileName + ' deleted.')
} catch (err) {
noErrorsDuringSaving = false
console.log('[ERROR] httpInterface -> Docs -> Save -> ' + filePath + '/' + fileName + ' could not be deleted.')
console.log('[ERROR] httpInterface -> Docs -> Save -> Resolve the issue that is preventing the Client to delete this file. Look at the error message below as a guide. At the UI you will need to delete this page again in order for the Client to retry next time you execute the docs.save command.')
console.log('[ERROR] httpInterface -> Docs -> Save -> err.stack = ' + err.stack)
@@ -483,6 +500,13 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
schemaDocument.updated = undefined
schemaDocument.created = undefined
let fileContent = JSON.stringify(schemaDocument, undefined, 4)
try {
fs.mkdirSync(filePath)
} catch (err) {
if (err.message.indexOf('file already exists') < 0) {
throw(err)
}
}
fs.writeFileSync(filePath + '/' + fileName, fileContent)
if (created === true) {
console.log('[SUCCESS] ' + filePath + '/' + fileName + ' created.')
@@ -491,15 +515,16 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
console.log('[SUCCESS] ' + filePath + '/' + fileName + ' updated.')
}
}
} catch (err) {
noErrorsDuringSaving = false
console.log('[ERROR] httpInterface -> Docs -> Save -> ' + filePath + '/' + fileName + ' could not be created / updated.')
console.log('[ERROR] httpInterface -> Docs -> Save -> Dont worry, the changes are still at the UI, but you will need to do 2 things: 1) Resolve the issue that is preventing the Client to write this file. Look at the error message below as a guide. 2) At the UI, locate this page and edit it with some small change again, so that is flagged that contains changes, otherwise those original changes will be ignored by the Client during the next docs.save command execution.')
console.log('[ERROR] httpInterface -> Docs -> Save -> err.stack = ' + err.stack)
}
}
}
}
return noErrorsDuringSaving
}
function cleanFileName(fileName) {
@@ -557,7 +582,7 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
await git.add('./*')
await git.commit(commitMessage)
await git.push('origin', currentBranch)
} catch(err) {
} catch (err) {
console.log('[ERROR] Error running Contribute.')
console.log(err.stack)
throw (err)
@@ -618,11 +643,15 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
async function update() {
let message = await doGit()
let customResponse = {
result: global.CUSTOM_OK_RESPONSE.result,
message: message
if (message !== undefined) {
let customResponse = {
result: global.CUSTOM_OK_RESPONSE.result,
message: message
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
} else {
respondWithContent(JSON.stringify(global.DEFAULT_FAIL_RESPONSE), httpResponse)
}
respondWithContent(JSON.stringify(customResponse), httpResponse)
}
async function doGit() {
@@ -634,7 +663,14 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
}
const git = simpleGit(options)
return await git.pull('upstream', currentBranch)
let message
try {
message = await git.pull('upstream', currentBranch)
return message
} catch (err) {
console.log('[ERROR] Error updating ' + currentBranch)
console.log(err.stack)
}
}
} catch (err) {
@@ -1351,8 +1387,10 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
let schema = JSON.stringify(schemaArray)
respondWithContent(schema, httpResponse)
} catch (err) {
console.log('Could not send Schema:', filePath, schemaType)
console.log(err.stack)
if (err.message.indexOf('no such file or directory') < 0) {
console.log('Could not send Schema:', filePath, schemaType)
console.log(err.stack)
}
respondWithContent("[]", httpResponse)
}
}
@@ -1,6 +0,0 @@
[
{
"type": "Ethereum Concept",
"definition": "This is the definition of an Ethereum Concept."
}
]
-6
View File
@@ -1,6 +0,0 @@
[
{
"type": "Ethereum Project",
"definition": "This is the definition for the Ethereum Project."
}
]
@@ -21,6 +21,48 @@
"text": "To solve this issue follow the following instructions on how to set up your GitHub.com credentials so that the system can automate the tasks needed to submit your contributions to the main repository of the Superalgos project.",
"updated": 1609945787577
},
{
"style": "Anchor",
"text": "Anchor Hierarchy APIs Not Found"
},
{
"style": "Error",
"text": "Github Crendentials are Missing. The Hierarchy APIs was not found at your workspace. Please create it following the guide below and try again."
},
{
"style": "Anchor",
"text": "Anchor Github API Node Not Found",
"updated": 1610559802944
},
{
"style": "Error",
"text": "Github Crendentials are Missing. The Hierarchy APIs does not have a child of type Github API. Please create it following the guide below and try again.",
"updated": 1610559836108
},
{
"style": "Anchor",
"text": "Anchor Config Property Username Not Found",
"updated": 1610559852624
},
{
"style": "Error",
"text": "Github Crendentials are Missing. The property username is missing or empty. Please create it following the guide below and try again.",
"updated": 1610559884041
},
{
"style": "Anchor",
"text": "Anchor Config Property Token Not Found",
"updated": 1610559914327
},
{
"style": "Error",
"text": "Github Crendentials are Missing. The property token is missing or empty. Please create it following the guide below and try again.",
"updated": 1610559900470
},
{
"style": "Text",
"text": ""
},
{
"style": "Title",
"text": "Applies to"
@@ -103,21 +103,21 @@ function newSuperalgosDocsCommmandInterface() {
/* Find the Username and Password */
let apisNode = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadsByType('APIs')
if (apisNode === undefined) {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Hierarchy APIs Not Found')
return
}
if (apisNode.githubAPI === undefined) {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github API Node Not Found')
return
}
let config = JSON.parse(apisNode.githubAPI.config)
if (config.username === undefined || config.username === "") {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Config Property Username Not Found')
return
}
if (config.token === undefined || config.token === "") {
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Github Credentials Missing')
UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'App Error - Github Credentials Missing', 'Anchor Config Property Token Not Found')
return
}