From owner-svn-src-all@freebsd.org Thu Nov 1 17:37:21 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5810310F981D; Thu, 1 Nov 2018 17:37:21 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 09E9A818DF; Thu, 1 Nov 2018 17:37:21 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C60831EED1; Thu, 1 Nov 2018 17:37:20 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wA1HbKV1082629; Thu, 1 Nov 2018 17:37:20 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wA1HbKjJ082627; Thu, 1 Nov 2018 17:37:20 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201811011737.wA1HbKjJ082627@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 1 Nov 2018 17:37:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r340012 - stable/12/stand/lua X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/12/stand/lua X-SVN-Commit-Revision: 340012 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Nov 2018 17:37:21 -0000 Author: kevans Date: Thu Nov 1 17:37:20 2018 New Revision: 340012 URL: https://svnweb.freebsd.org/changeset/base/340012 Log: MFC r339849: 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. Approved by: re (gjb) Modified: stable/12/stand/lua/core.lua Directory Properties: stable/12/ (props changed) Modified: stable/12/stand/lua/core.lua ============================================================================== --- stable/12/stand/lua/core.lua Thu Nov 1 17:36:42 2018 (r340011) +++ stable/12/stand/lua/core.lua Thu Nov 1 17:37:20 2018 (r340012) @@ -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