Skip to content

Commit

Permalink
Stop with improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Jan 2, 2024
1 parent 27a6b0a commit 99ec0be
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions R/readEuCodedFiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ readEuCodedFiles <- function(
"input file %d/%d: %s\n", i, length(input.files), input.file
))

inspectionData <- try(readEuCodedFile(input.file, dbg = dbg, ...))
inspectionData <- try(
readEuCodedFile(input.file, dbg = dbg, ...),
silent = TRUE
)

# Return NULL if an error occurred
if (kwb.utils::isTryError(inspectionData)) {
return(NULL)
return(inspectionData)

Check warning on line 43 in R/readEuCodedFiles.R

View check run for this annotation

Codecov / codecov/patch

R/readEuCodedFiles.R#L43

Added line #L43 was not covered by tests
}

if (append.file.names) {
Expand All @@ -49,18 +52,29 @@ readEuCodedFiles <- function(

inspectionData
})

failed <- sapply(result, is.null)
failed <- sapply(result, kwb.utils::isTryError)

# Give a warning about occurred errors
if (any(failed)) {

warning(call. = FALSE, sprintf(
"readEuCodedFile() returned with error for the following %d files:\n%s",
sum(failed), kwb.utils::stringList(basename(input.files[failed]))
))
stop(
call. = FALSE,
"Import aborted due to errors in ",
sum(failed),
" files:\n\n*** ",
paste0(
basename(input.files[failed]),
":\n",
as.character(result[failed]),
collapse = "\n*** "

Check warning on line 69 in R/readEuCodedFiles.R

View check run for this annotation

Codecov / codecov/patch

R/readEuCodedFiles.R#L60-L69

Added lines #L60 - L69 were not covered by tests
),
"\nYou may either\n",
"- correct the files,\n",
"- rename them so that they do not end in '.txt' any more, or\n",
"- remove them from the input folder."

Check warning on line 74 in R/readEuCodedFiles.R

View check run for this annotation

Codecov / codecov/patch

R/readEuCodedFiles.R#L71-L74

Added lines #L71 - L74 were not covered by tests
)
}

# Create valid list element names
elements <- kwb.utils::substSpecialChars(basename(input.files))

Expand Down

0 comments on commit 99ec0be

Please sign in to comment.