Skip to content

Commit

Permalink
Add key when warning for missing fields; closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmclean committed Apr 24, 2018
1 parent 7b17ef8 commit 09a0d5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
40 changes: 24 additions & 16 deletions R/04InternalFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
if (length(rfields) > 0L) {
ok <- vapply(rfields, function(f) any(f %in% fields), FALSE)
if (any(!ok)){
if (check == 'warn'){
warning(sprintf(ngettext(sum(!ok),
"A bibentry of bibtype %s has to specify the field: %s",
key <- attr(x, "key")
if (is.null(key))
key <- ""
else
key <- paste0(key, ": ")
msg <- sprintf(ngettext(sum(!ok),
"%sA bibentry of bibtype %s has to specify the field: %s",
"A bibentry of bibtype %s has to specify the fields: %s"),
sQuote(bibtype), paste(rfields[!ok], collapse = ", ")),
domain = NA)
key, sQuote(bibtype), paste(rfields[!ok], collapse = ", "))
if (check == 'warn'){
warning(msg, domain = NA, call. = FALSE)
return(NULL)
}else{
stop(sprintf(ngettext(sum(!ok),
"A bibentry of bibtype %s has to specify the field: %s",
"A bibentry of bibtype %s has to specify the fields: %s"),
sQuote(bibtype), paste(rfields[!ok], collapse = ", ")),
domain = NA)
}
}else
stop(msg, domain = NA)
}
}
}
Expand Down Expand Up @@ -940,14 +940,22 @@ MakeBibEntry <- function(x, to.person = TRUE){
if (type != 'set')
tdate <- ProcessDates(y)

tryCatch(BibEntry(bibtype = type, key = key, dateobj = tdate, other = y),
withCallingHandlers(tryCatch(BibEntry(bibtype = type, key = key,
dateobj = tdate, other = y),
error = function(e){
message(sprintf("Ignoring entry '%s' %sbecause:\n\t%s\n",
message(sprintf("Ignoring entry '%s' %sbecause:\n\t%s",
key,
line.no,
conditionMessage(e)))
conditionMessage(e)), domain = NA)
NULL
})
}),
warning = function(w){
warning(sprintf("%s %s:\n\t%s",
key,
line.no,
conditionMessage(w)), domain = NA, call. = FALSE)
invokeRestart("muffleWarning")
})
}

#' @keywords internal
Expand Down
7 changes: 7 additions & 0 deletions inst/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ which defaults to `BibOptions()$ignore.case` (`TRUE`) so that case is
ignore when checking for duplicate fields (h/t Justin Calabrese #47)
* Improved warning message when printing entries with unknown
LaTeX macros (the entry key is now included). (h/t Justin Calabrese #49)
* The entry key is now included in warning messages when entries are
missing fields and `BibOptions()$check.entries == "warn"` (h/t Justin
Calabrese #48)

BUG FIXES

* Entries are now only checked once to ensure all required
fields are present in `ReadBib`

Changes in Version 1.1.0 (2018-04-02)
--------------------------------------------------------
Expand Down

0 comments on commit 09a0d5d

Please sign in to comment.