show an error if the main file cannot be found

also improve logic for detecting the main file, if there's only one file
it must be the main file.
This commit is contained in:
Brian Gough 2017-10-17 15:47:50 +01:00
parent 67b13d2583
commit f70ab03bd8
2 changed files with 22 additions and 3 deletions

View file

@ -29,7 +29,11 @@ module.exports = ClsiManager =
sendRequestOnce: (project_id, user_id, options = {}, callback = (error, status, outputFiles, clsiServerId, validationProblems) ->) -> sendRequestOnce: (project_id, user_id, options = {}, callback = (error, status, outputFiles, clsiServerId, validationProblems) ->) ->
ClsiManager._buildRequest project_id, options, (error, req) -> ClsiManager._buildRequest project_id, options, (error, req) ->
return callback(error) if error? if error?
if error.message is "no main file specified"
return callback(null, "validation-problems", null, null, {mainFile:error.message})
else
return callback(error)
logger.log project_id: project_id, "sending compile to CLSI" logger.log project_id: project_id, "sending compile to CLSI"
ClsiFormatChecker.checkRecoursesForProblems req.compile?.resources, (err, validationProblems)-> ClsiFormatChecker.checkRecoursesForProblems req.compile?.resources, (err, validationProblems)->
if err? if err?
@ -206,9 +210,12 @@ module.exports = ClsiManager =
resources = [] resources = []
rootResourcePath = null rootResourcePath = null
rootResourcePathOverride = null rootResourcePathOverride = null
hasMainFile = false
numberOfDocsInProject = 0
for path, doc of docs for path, doc of docs
path = path.replace(/^\//, "") # Remove leading / path = path.replace(/^\//, "") # Remove leading /
numberOfDocsInProject++
if doc.lines? # add doc to resources unless it is just a stub entry if doc.lines? # add doc to resources unless it is just a stub entry
resources.push resources.push
path: path path: path
@ -217,11 +224,20 @@ module.exports = ClsiManager =
rootResourcePath = path rootResourcePath = path
if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString() if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString()
rootResourcePathOverride = path rootResourcePathOverride = path
if path is "main.tex"
hasMainFile = true
rootResourcePath = rootResourcePathOverride if rootResourcePathOverride? rootResourcePath = rootResourcePathOverride if rootResourcePathOverride?
if !rootResourcePath? if !rootResourcePath?
if hasMainFile
logger.warn {project_id}, "no root document found, setting to main.tex" logger.warn {project_id}, "no root document found, setting to main.tex"
rootResourcePath = "main.tex" rootResourcePath = "main.tex"
else if numberOfDocsInProject is 1 # only one file, must be the main document
for path, doc of docs
rootResourcePath = path.replace(/^\//, "") # Remove leading /
logger.warn {project_id, rootResourcePath: rootResourcePath}, "no root document found, single document in project"
else
return callback new Error("no main file specified")
for path, file of files for path, file of files
path = path.replace(/^\//, "") # Remove leading / path = path.replace(/^\//, "") # Remove leading /

View file

@ -317,6 +317,9 @@ div.full-size.pdf(ng-controller="PdfController")
div div
li(ng-repeat="entry in pdf.validation.conflictedPaths") {{ '/'+entry['path'] }} li(ng-repeat="entry in pdf.validation.conflictedPaths") {{ '/'+entry['path'] }}
.alert.alert-danger(ng-show="pdf.validation.mainFile")
strong #{translate("main_file_not_found")}
span #{translate("please_set_main_file")}
.pdf-errors(ng-switch-when="errors") .pdf-errors(ng-switch-when="errors")