Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Biggins/ErrorHandling
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {}; -- Tables taken from the LDSverse module: local bomBooks = { ["Title Page"] = {"ttl", "ttlpg", "title", "title-page", "title_page"}, ["Testimony of Three Witnesses"] = {"three", "3witnesses"}, ["Testimony of Eight Witnesses"] = {"eight", "8witnesses"}, ["1 Nephi"] = {"1-ne", "1_ne", "1ne", "1 ne"}, ["2 Nephi"] = {"2-ne", "2_ne", "2ne", "2 ne"}, ["Jacob"] = {"jac"}, ["Enos"] = {"en"}, ["Jarom"] = {"jar"}, ["Omni"] = {"omn"}, ["Words of Mormon"] = {"w-of-m", "wofm", "w_of_m"}, ["Mosiah"] = {}, ["Alma"] = {}, ["Helaman"] = {"hel"}, ["3 Nephi"] = {"3-ne", "3_ne", "3ne", "3 ne"}, ["4 Nephi"] = {"4-ne", "4_ne", "4ne", "4 ne"}, ["Mormon"] = {"morm", "mormon"}, ["Ether"] = {}, ["Moroni"] = {"moro", "moroni"} } local dcBooks = { ["The Doctrine and Covenants"] = {"dc", "d-c", "d&c", "d & c", "doctrine and covenants"}, ["Official Declaration"] = {"od", "official declaration"} } local lofBooks = { ["Lectures on Faith"] = {"lof", "l-o-f", "l-of-f", "loff", "lectures"} } local pogpBooks = { ["Moses"] = {}, ["Abraham"] = {"abr", "fac-1", "fac1", "fac-2", "fac2", "fac-3", "fac3"}, ["JST Matthew"] = {"js-m", "jsm", "joseph smith matthew", "jst matt", "jst-matt", "jst-matthew", "js matthew"}, -- NB: This is a special case! ["History"] = {"js-h", "jsh", "js history", "joseph smith history", "js-hist", "js hist"}, ["Articles of Faith"] = {"a-of-f", "a_of_f", "aoff", "the articles of faith"} } local bibleBooks = { ["Genesis"] = {"gen", "gn"}, ["Exodus"] = {"exod", "ex"}, ["Leviticus"] = {"lev", "lv"}, ["Numbers"] = {"num", "nm"}, ["Deuteronomy"] = {"deut", "dt"}, ["Joshua"] = {"josh" , "jo"}, ["Judges"] = {"judg", "jgs"}, ["Ruth"] = {"ru", "ruth"}, ["1 Samuel"] = {"1sam", "1sm", "1_sam", "1-sam", "1 sam"}, ["2 Samuel"] = {"2sam", "2sm", "2_sam", "2-sam", "2 sam"}, ["1 Kings"] = {"1kgs", "1-kgs", "1_kgs", "1 kgs"}, ["2 Kings"] = {"2kgs", "2-kgs", "2_kgs", "2 kgs"}, ["1 Chronicles"] = {"1chron", "1chr", "1-chr", "1_chr", "1 chr"}, ["2 Chronicles"] = {"2chron", "2chr", "2-chr", "2_chr", "2 chr"}, ["Ezra"] = {}, ["Nehemiah"] = {"neh"}, ["Esther"] = {"est", "esth"}, ["Job"] = {"jb"}, ["Psalms"] = {"ps", "pss", "psalm"}, ["Proverbs"] = {"prov", "prv"}, ["Ecclesiastes"] = {"eccles", "eccl", "qoheleth"}, ["Song of Solomon"] = {"songofsol", "songofsongs", "song", "songs", "sg", "canticles", "canticleofcanticles", "songs of solomon"}, ["Isaiah"] = {"isa", "is"}, ["Jeremiah"] = {"jer"}, ["Lamentations"] = {"lam"}, ["Ezekiel"] = {"ezek", "ez"}, ["Daniel"] = {"dan", "dn"}, ["Hosea"] = {"hos"}, ["Joel"] = {"jl"}, ["Amos"] = {"am"}, ["Obadiah"] = {"obad", "ob"}, ["Jonah"] = {"jon"}, ["Micah"] = {"mic", "mi"}, ["Nahum"] = {"nah", "na"}, ["Habakkuk"] = {"hab", "hb"}, ["Zephaniah"] = {"zeph", "zep"}, ["Haggai"] = {"hag", "hg"}, ["Zechariah"] = {"zech", "zec", "zach", "zac"}, ["Malachi"] = {"mal"}, ["Matthew"] = {"matt", "mt"}, ["Mark"] = {"mk"}, ["Luke"] = {"lk"}, ["John"] = {"jn"}, ["Acts"] = {"actsoftheapostles", "the acts", "acts of the apostles", "the acts of the apostles"}, ["Romans"] = {"rom", "roman"}, ["1 Corinthians"] = {"1cor", "1-cor", "1_cor", "1 cor"}, ["2 Corinthians"] = {"2cor", "2-cor", "2_cor", "2 cor"}, ["Galatians"] = {"gal"}, ["Ephesians"] = {"eph"}, ["Philippians"] = {"phil", "philip"}, ["Colossians"] = {"col"}, ["1 Thessalonians"] = {"1thess", "1thes", "1-thes", "1_thes", "1-thess", "1_thess", "1 thess", "1 thes"}, ["2 Thessalonians"] = {"2thess", "2thes", "2-thes", "2_thes", "2-thess", "2_thess", "2 thess", "2 thes"}, ["1 Timothy"] = {"1tim", "1tm", "1-tim", "1_tim", "1 tim"}, ["2 Timothy"] = {"2tim", "2tm", "2-tim", "2_tim", "2 tim"}, ["Titus"] = {"ti"}, ["Philemon"] = {"philem", "phlm"}, ["Hebrews"] = {"heb", "hebrew"}, ["James"] = {"jas"}, ["1 Peter"] = {"1pet", "1pt", "1-pet", "1_pet", "1 pet"}, ["2 Peter"] = {"2pet", "2pt", "2-pet", "2_pet", "2 pet"}, ["1 John"] = {"1jn", "1-jn", "1_jn", "1 jn"}, ["2 John"] = {"2jn", "2-jn", "2_jn", "2 jn"}, ["3 John"] = {"3jn", "3-jn", "3_jn", "3 jn"}, ["Jude"] = {}, ["Revelation"] = {"rev", "apocalypse", "apoc", "rv", "revelations"} } -- This table holds the titles of the Standard Works themselves, as found on WS local standardWorks = { ["Book of Mormon (1981)"] = bomBooks, ["The Doctrine and Covenants"] = dcBooks, ["The Pearl of Great Price (1913)"] = pogpBooks, ["Bible (King James)"] = bibleBooks, ["Lectures on Faith"] = lofBooks } local function xpcallTest(param) if not param then param = "nil" end error("I deliberately threw an error in xpcallTest! (Lua v." .. _VERSION .. ") (ps param was " .. param .. ")") return "It's alll good! " .. param .. "<br>" end local function assertTest(param) --assert(false, "I deliberately asserted something I knew to be false!") assert(param, "Oh no: you passed 'false' to assertTest (or no parameter at all)!<br>") return "Assertion true; everything's a-ok!<br>" end local function errorTest(param) error("I deliberately threw an error in errorTest!<br>") end local function handler(message) return "Oh I handled it alright! (Message: " .. message .. ")<br>" end local function getAliasRows(t) local aliasRows = "" for k,v in pairs(t) do aliasRows = aliasRows .. "| " .. k .. "<br>| " .. table.concat(v, ", ") .. "<br>" end return aliasRows end local function countKeys(t) local i = 0 for k,v in pairs(t) do i = i+1 end return i end function p.getBookAliasesWikiTable(standardWork) local wikiTable = [[{| class="wikitable sortable mw-collapsible mw-collapsed" |+ class="nowrap" |LDS Template Book Name Aliases ! Standard Work !! Book !! Aliases ]] for sw, bookList in pairs(standardWorks) do wikiTable = wikiTable .. '|-\n|rowspan="' .. countKeys(bookList) .. '"|' .. sw .. "\n" for book, aliases in pairs(bookList) do wikiTable = wikiTable .. "| " .. book .. "\n| " .. table.concat(aliases, ", ") .. "\n|-\n" end end wikiTable = wikiTable .. "|}" return wikiTable end function p.main(frame) --local params = frame.args --local param = params[1] local r = "" local success, rVal success, rVal = xpcall(xpcallTest, handler, "test param") if (success) then return rVal end r = r .. rVal .. " " success, rVal = pcall(assertTest, param) if (success) then return rVal end r = r .. rVal .. " " success, rVal = pcall(errorTest, param) if (success) then return rVal end r = r .. rVal .. " " return "Sorry, bud, but something went wrong!<br>" .. r end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Biggins/ErrorHandling/doc
(
edit
)