Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Oct 2018 02:58:31 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r339849 - head/stand/lua
Message-ID:  <201810290258.w9T2wVid082479@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Oct 29 02:58:30 2018
New Revision: 339849
URL: https://svnweb.freebsd.org/changeset/base/339849

Log:
  lualoader: Fix try_include error handling
  
  The previous iteration of try_include attempted to be 'friendly' and error()
  out if we hit an error that wasn't ENOENT. This was semi-OK, but fragile as
  it relied on pattern matching the error message.
  
  Move the responsibility for handling failure to the caller. Following
  a common lua pattern, we'll return the return value of the underlying
  require() on success, or false and an error message.
  
  Reported by:	bcran
  MFC after:	3 days

Modified:
  head/stand/lua/core.lua

Modified: head/stand/lua/core.lua
==============================================================================
--- head/stand/lua/core.lua	Sun Oct 28 23:54:05 2018	(r339848)
+++ head/stand/lua/core.lua	Mon Oct 29 02:58:30 2018	(r339849)
@@ -66,23 +66,15 @@ end
 
 
 -- Globals
--- try_include will return the loaded module on success, or nil on failure.
--- A message will also be printed on failure, with one exception: non-verbose
--- loading will suppress 'module not found' errors.
+-- try_include will return the loaded module on success, or false and the error
+-- message on failure.
 function try_include(module)
 	local status, ret = pcall(require, module)
 	-- ret is the module if we succeeded.
 	if status then
 		return ret
 	end
-	-- Otherwise, ret is just a message; filter out ENOENT unless we're
-	-- doing a verbose load. As a consequence, try_include prior to loading
-	-- configuration will not display 'module not found'. All other errors
-	-- in loading will be printed.
-	if config.verbose or ret:match("^module .+ not found") == nil then
-		error(ret, 2)
-	end
-	return nil
+	return false, ret
 end
 
 -- Module exports



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810290258.w9T2wVid082479>