Merge pull request #2628 from emekoi/error-unexpected

windows.unexpectedError prints a human friendly string
master
Andrew Kelley 2019-06-06 12:37:51 -04:00 committed by GitHub
commit fb5e03b983
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 415 additions and 1 deletions

View File

@ -630,9 +630,11 @@ set(ZIG_STD_FILES
"os/windows/bits.zig"
"os/windows/error.zig"
"os/windows/kernel32.zig"
"os/windows/lang.zig"
"os/windows/ntdll.zig"
"os/windows/ole32.zig"
"os/windows/shell32.zig"
"os/windows/sublang.zig"
"os/zen.zig"
"packed_int_array.zig"
"pdb.zig"

View File

@ -756,11 +756,23 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
return result;
}
inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID {
return (s << 10) | p;
}
/// Call this when you made a windows DLL call or something that does SetLastError
/// and you get an unexpected error.
pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
if (std.os.unexpected_error_tracing) {
std.debug.warn("unexpected GetLastError(): {}\n", err);
// 614 is the length of the longest windows error desciption
var buf_u16: [614]u16 = undefined;
var buf_u8: [614]u8 = undefined;
var len = kernel32.FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT),
buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null);
_ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;
std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]);
std.debug.dumpCurrentStackTrace(null);
}
return error.Unexpected;

View File

@ -6,6 +6,8 @@ const assert = std.debug.assert;
const maxInt = std.math.maxInt;
pub const ERROR = @import("error.zig");
pub const LANG = @import("lang.zig");
pub const SUBLANG = @import("sublang.zig");
/// The standard input device. Initially, this is the console input buffer, CONIN$.
pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
@ -55,6 +57,10 @@ pub const ULONG = u32;
pub const LONG = i32;
pub const ULONGLONG = u64;
pub const LONGLONG = i64;
pub const HLOCAL = HANDLE;
pub const LANGID = c_ushort;
pub const va_list = *@OpaqueType();
pub const TRUE = 1;
pub const FALSE = 0;
@ -525,3 +531,11 @@ pub const COINIT = extern enum {
/// > this expansion applies to the total length.
/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
pub const PATH_MAX_WIDE = 32767;
pub const FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
pub const FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
pub const FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
pub const FORMAT_MESSAGE_FROM_STRING = 0x00000400;
pub const FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
pub const FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
pub const FORMAT_MESSAGE_MAX_WIDTH_MASK = 0x000000FF;

View File

@ -50,6 +50,8 @@ pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*]const u16, lpFi
pub extern "kernel32" stdcallcc fn FindClose(hFindFile: HANDLE) BOOL;
pub extern "kernel32" stdcallcc fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) BOOL;
pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) DWORD;
pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*]u16) BOOL;
pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;

140
std/os/windows/lang.zig Normal file
View File

@ -0,0 +1,140 @@
pub const NEUTRAL = 0x00;
pub const INVARIANT = 0x7f;
pub const AFRIKAANS = 0x36;
pub const ALBANIAN = 0x1c;
pub const ALSATIAN = 0x84;
pub const AMHARIC = 0x5e;
pub const ARABIC = 0x01;
pub const ARMENIAN = 0x2b;
pub const ASSAMESE = 0x4d;
pub const AZERI = 0x2c;
pub const AZERBAIJANI = 0x2c;
pub const BANGLA = 0x45;
pub const BASHKIR = 0x6d;
pub const BASQUE = 0x2d;
pub const BELARUSIAN = 0x23;
pub const BENGALI = 0x45;
pub const BRETON = 0x7e;
pub const BOSNIAN = 0x1a;
pub const BOSNIAN_NEUTRAL = 0x781a;
pub const BULGARIAN = 0x02;
pub const CATALAN = 0x03;
pub const CENTRAL_KURDISH = 0x92;
pub const CHEROKEE = 0x5c;
pub const CHINESE = 0x04;
pub const CHINESE_SIMPLIFIED = 0x04;
pub const CHINESE_TRADITIONAL = 0x7c04;
pub const CORSICAN = 0x83;
pub const CROATIAN = 0x1a;
pub const CZECH = 0x05;
pub const DANISH = 0x06;
pub const DARI = 0x8c;
pub const DIVEHI = 0x65;
pub const DUTCH = 0x13;
pub const ENGLISH = 0x09;
pub const ESTONIAN = 0x25;
pub const FAEROESE = 0x38;
pub const FARSI = 0x29;
pub const FILIPINO = 0x64;
pub const FINNISH = 0x0b;
pub const FRENCH = 0x0c;
pub const FRISIAN = 0x62;
pub const FULAH = 0x67;
pub const GALICIAN = 0x56;
pub const GEORGIAN = 0x37;
pub const GERMAN = 0x07;
pub const GREEK = 0x08;
pub const GREENLANDIC = 0x6f;
pub const GUJARATI = 0x47;
pub const HAUSA = 0x68;
pub const HAWAIIAN = 0x75;
pub const HEBREW = 0x0d;
pub const HINDI = 0x39;
pub const HUNGARIAN = 0x0e;
pub const ICELANDIC = 0x0f;
pub const IGBO = 0x70;
pub const INDONESIAN = 0x21;
pub const INUKTITUT = 0x5d;
pub const IRISH = 0x3c;
pub const ITALIAN = 0x10;
pub const JAPANESE = 0x11;
pub const KANNADA = 0x4b;
pub const KASHMIRI = 0x60;
pub const KAZAK = 0x3f;
pub const KHMER = 0x53;
pub const KICHE = 0x86;
pub const KINYARWANDA = 0x87;
pub const KONKANI = 0x57;
pub const KOREAN = 0x12;
pub const KYRGYZ = 0x40;
pub const LAO = 0x54;
pub const LATVIAN = 0x26;
pub const LITHUANIAN = 0x27;
pub const LOWER_SORBIAN = 0x2e;
pub const LUXEMBOURGISH = 0x6e;
pub const MACEDONIAN = 0x2f;
pub const MALAY = 0x3e;
pub const MALAYALAM = 0x4c;
pub const MALTESE = 0x3a;
pub const MANIPURI = 0x58;
pub const MAORI = 0x81;
pub const MAPUDUNGUN = 0x7a;
pub const MARATHI = 0x4e;
pub const MOHAWK = 0x7c;
pub const MONGOLIAN = 0x50;
pub const NEPALI = 0x61;
pub const NORWEGIAN = 0x14;
pub const OCCITAN = 0x82;
pub const ODIA = 0x48;
pub const ORIYA = 0x48;
pub const PASHTO = 0x63;
pub const PERSIAN = 0x29;
pub const POLISH = 0x15;
pub const PORTUGUESE = 0x16;
pub const PULAR = 0x67;
pub const PUNJABI = 0x46;
pub const QUECHUA = 0x6b;
pub const ROMANIAN = 0x18;
pub const ROMANSH = 0x17;
pub const RUSSIAN = 0x19;
pub const SAKHA = 0x85;
pub const SAMI = 0x3b;
pub const SANSKRIT = 0x4f;
pub const SCOTTISH_GAELIC = 0x91;
pub const SERBIAN = 0x1a;
pub const SERBIAN_NEUTRAL = 0x7c1a;
pub const SINDHI = 0x59;
pub const SINHALESE = 0x5b;
pub const SLOVAK = 0x1b;
pub const SLOVENIAN = 0x24;
pub const SOTHO = 0x6c;
pub const SPANISH = 0x0a;
pub const SWAHILI = 0x41;
pub const SWEDISH = 0x1d;
pub const SYRIAC = 0x5a;
pub const TAJIK = 0x28;
pub const TAMAZIGHT = 0x5f;
pub const TAMIL = 0x49;
pub const TATAR = 0x44;
pub const TELUGU = 0x4a;
pub const THAI = 0x1e;
pub const TIBETAN = 0x51;
pub const TIGRIGNA = 0x73;
pub const TIGRINYA = 0x73;
pub const TSWANA = 0x32;
pub const TURKISH = 0x1f;
pub const TURKMEN = 0x42;
pub const UIGHUR = 0x80;
pub const UKRAINIAN = 0x22;
pub const UPPER_SORBIAN = 0x2e;
pub const URDU = 0x20;
pub const UZBEK = 0x43;
pub const VALENCIAN = 0x03;
pub const VIETNAMESE = 0x2a;
pub const WELSH = 0x52;
pub const WOLOF = 0x88;
pub const XHOSA = 0x34;
pub const YAKUT = 0x85;
pub const YI = 0x78;
pub const YORUBA = 0x6a;
pub const ZULU = 0x35;

244
std/os/windows/sublang.zig Normal file
View File

@ -0,0 +1,244 @@
pub const NEUTRAL = 0x00;
pub const DEFAULT = 0x01;
pub const SYS_DEFAULT = 0x02;
pub const CUSTOM_DEFAULT = 0x03;
pub const CUSTOM_UNSPECIFIED = 0x04;
pub const UI_CUSTOM_DEFAULT = 0x05;
pub const AFRIKAANS_SOUTH_AFRICA = 0x01;
pub const ALBANIAN_ALBANIA = 0x01;
pub const ALSATIAN_FRANCE = 0x01;
pub const AMHARIC_ETHIOPIA = 0x01;
pub const ARABIC_SAUDI_ARABIA = 0x01;
pub const ARABIC_IRAQ = 0x02;
pub const ARABIC_EGYPT = 0x03;
pub const ARABIC_LIBYA = 0x04;
pub const ARABIC_ALGERIA = 0x05;
pub const ARABIC_MOROCCO = 0x06;
pub const ARABIC_TUNISIA = 0x07;
pub const ARABIC_OMAN = 0x08;
pub const ARABIC_YEMEN = 0x09;
pub const ARABIC_SYRIA = 0x0a;
pub const ARABIC_JORDAN = 0x0b;
pub const ARABIC_LEBANON = 0x0c;
pub const ARABIC_KUWAIT = 0x0d;
pub const ARABIC_UAE = 0x0e;
pub const ARABIC_BAHRAIN = 0x0f;
pub const ARABIC_QATAR = 0x10;
pub const ARMENIAN_ARMENIA = 0x01;
pub const ASSAMESE_INDIA = 0x01;
pub const AZERI_LATIN = 0x01;
pub const AZERI_CYRILLIC = 0x02;
pub const AZERBAIJANI_AZERBAIJAN_LATIN = 0x01;
pub const AZERBAIJANI_AZERBAIJAN_CYRILLIC = 0x02;
pub const BANGLA_INDIA = 0x01;
pub const BANGLA_BANGLADESH = 0x02;
pub const BASHKIR_RUSSIA = 0x01;
pub const BASQUE_BASQUE = 0x01;
pub const BELARUSIAN_BELARUS = 0x01;
pub const BENGALI_INDIA = 0x01;
pub const BENGALI_BANGLADESH = 0x02;
pub const BOSNIAN_BOSNIA_HERZEGOVINA_LATIN = 0x05;
pub const BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 0x08;
pub const BRETON_FRANCE = 0x01;
pub const BULGARIAN_BULGARIA = 0x01;
pub const CATALAN_CATALAN = 0x01;
pub const CENTRAL_KURDISH_IRAQ = 0x01;
pub const CHEROKEE_CHEROKEE = 0x01;
pub const CHINESE_TRADITIONAL = 0x01;
pub const CHINESE_SIMPLIFIED = 0x02;
pub const CHINESE_HONGKONG = 0x03;
pub const CHINESE_SINGAPORE = 0x04;
pub const CHINESE_MACAU = 0x05;
pub const CORSICAN_FRANCE = 0x01;
pub const CZECH_CZECH_REPUBLIC = 0x01;
pub const CROATIAN_CROATIA = 0x01;
pub const CROATIAN_BOSNIA_HERZEGOVINA_LATIN = 0x04;
pub const DANISH_DENMARK = 0x01;
pub const DARI_AFGHANISTAN = 0x01;
pub const DIVEHI_MALDIVES = 0x01;
pub const DUTCH = 0x01;
pub const DUTCH_BELGIAN = 0x02;
pub const ENGLISH_US = 0x01;
pub const ENGLISH_UK = 0x02;
pub const ENGLISH_AUS = 0x03;
pub const ENGLISH_CAN = 0x04;
pub const ENGLISH_NZ = 0x05;
pub const ENGLISH_EIRE = 0x06;
pub const ENGLISH_SOUTH_AFRICA = 0x07;
pub const ENGLISH_JAMAICA = 0x08;
pub const ENGLISH_CARIBBEAN = 0x09;
pub const ENGLISH_BELIZE = 0x0a;
pub const ENGLISH_TRINIDAD = 0x0b;
pub const ENGLISH_ZIMBABWE = 0x0c;
pub const ENGLISH_PHILIPPINES = 0x0d;
pub const ENGLISH_INDIA = 0x10;
pub const ENGLISH_MALAYSIA = 0x11;
pub const ENGLISH_SINGAPORE = 0x12;
pub const ESTONIAN_ESTONIA = 0x01;
pub const FAEROESE_FAROE_ISLANDS = 0x01;
pub const FILIPINO_PHILIPPINES = 0x01;
pub const FINNISH_FINLAND = 0x01;
pub const FRENCH = 0x01;
pub const FRENCH_BELGIAN = 0x02;
pub const FRENCH_CANADIAN = 0x03;
pub const FRENCH_SWISS = 0x04;
pub const FRENCH_LUXEMBOURG = 0x05;
pub const FRENCH_MONACO = 0x06;
pub const FRISIAN_NETHERLANDS = 0x01;
pub const FULAH_SENEGAL = 0x02;
pub const GALICIAN_GALICIAN = 0x01;
pub const GEORGIAN_GEORGIA = 0x01;
pub const GERMAN = 0x01;
pub const GERMAN_SWISS = 0x02;
pub const GERMAN_AUSTRIAN = 0x03;
pub const GERMAN_LUXEMBOURG = 0x04;
pub const GERMAN_LIECHTENSTEIN = 0x05;
pub const GREEK_GREECE = 0x01;
pub const GREENLANDIC_GREENLAND = 0x01;
pub const GUJARATI_INDIA = 0x01;
pub const HAUSA_NIGERIA_LATIN = 0x01;
pub const HAWAIIAN_US = 0x01;
pub const HEBREW_ISRAEL = 0x01;
pub const HINDI_INDIA = 0x01;
pub const HUNGARIAN_HUNGARY = 0x01;
pub const ICELANDIC_ICELAND = 0x01;
pub const IGBO_NIGERIA = 0x01;
pub const INDONESIAN_INDONESIA = 0x01;
pub const INUKTITUT_CANADA = 0x01;
pub const INUKTITUT_CANADA_LATIN = 0x02;
pub const IRISH_IRELAND = 0x02;
pub const ITALIAN = 0x01;
pub const ITALIAN_SWISS = 0x02;
pub const JAPANESE_JAPAN = 0x01;
pub const KANNADA_INDIA = 0x01;
pub const KASHMIRI_SASIA = 0x02;
pub const KASHMIRI_INDIA = 0x02;
pub const KAZAK_KAZAKHSTAN = 0x01;
pub const KHMER_CAMBODIA = 0x01;
pub const KICHE_GUATEMALA = 0x01;
pub const KINYARWANDA_RWANDA = 0x01;
pub const KONKANI_INDIA = 0x01;
pub const KOREAN = 0x01;
pub const KYRGYZ_KYRGYZSTAN = 0x01;
pub const LAO_LAO = 0x01;
pub const LATVIAN_LATVIA = 0x01;
pub const LITHUANIAN = 0x01;
pub const LOWER_SORBIAN_GERMANY = 0x02;
pub const LUXEMBOURGISH_LUXEMBOURG = 0x01;
pub const MACEDONIAN_MACEDONIA = 0x01;
pub const MALAY_MALAYSIA = 0x01;
pub const MALAY_BRUNEI_DARUSSALAM = 0x02;
pub const MALAYALAM_INDIA = 0x01;
pub const MALTESE_MALTA = 0x01;
pub const MAORI_NEW_ZEALAND = 0x01;
pub const MAPUDUNGUN_CHILE = 0x01;
pub const MARATHI_INDIA = 0x01;
pub const MOHAWK_MOHAWK = 0x01;
pub const MONGOLIAN_CYRILLIC_MONGOLIA = 0x01;
pub const MONGOLIAN_PRC = 0x02;
pub const NEPALI_INDIA = 0x02;
pub const NEPALI_NEPAL = 0x01;
pub const NORWEGIAN_BOKMAL = 0x01;
pub const NORWEGIAN_NYNORSK = 0x02;
pub const OCCITAN_FRANCE = 0x01;
pub const ODIA_INDIA = 0x01;
pub const ORIYA_INDIA = 0x01;
pub const PASHTO_AFGHANISTAN = 0x01;
pub const PERSIAN_IRAN = 0x01;
pub const POLISH_POLAND = 0x01;
pub const PORTUGUESE = 0x02;
pub const PORTUGUESE_BRAZILIAN = 0x01;
pub const PULAR_SENEGAL = 0x02;
pub const PUNJABI_INDIA = 0x01;
pub const PUNJABI_PAKISTAN = 0x02;
pub const QUECHUA_BOLIVIA = 0x01;
pub const QUECHUA_ECUADOR = 0x02;
pub const QUECHUA_PERU = 0x03;
pub const ROMANIAN_ROMANIA = 0x01;
pub const ROMANSH_SWITZERLAND = 0x01;
pub const RUSSIAN_RUSSIA = 0x01;
pub const SAKHA_RUSSIA = 0x01;
pub const SAMI_NORTHERN_NORWAY = 0x01;
pub const SAMI_NORTHERN_SWEDEN = 0x02;
pub const SAMI_NORTHERN_FINLAND = 0x03;
pub const SAMI_LULE_NORWAY = 0x04;
pub const SAMI_LULE_SWEDEN = 0x05;
pub const SAMI_SOUTHERN_NORWAY = 0x06;
pub const SAMI_SOUTHERN_SWEDEN = 0x07;
pub const SAMI_SKOLT_FINLAND = 0x08;
pub const SAMI_INARI_FINLAND = 0x09;
pub const SANSKRIT_INDIA = 0x01;
pub const SCOTTISH_GAELIC = 0x01;
pub const SERBIAN_BOSNIA_HERZEGOVINA_LATIN = 0x06;
pub const SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC = 0x07;
pub const SERBIAN_MONTENEGRO_LATIN = 0x0b;
pub const SERBIAN_MONTENEGRO_CYRILLIC = 0x0c;
pub const SERBIAN_SERBIA_LATIN = 0x09;
pub const SERBIAN_SERBIA_CYRILLIC = 0x0a;
pub const SERBIAN_CROATIA = 0x01;
pub const SERBIAN_LATIN = 0x02;
pub const SERBIAN_CYRILLIC = 0x03;
pub const SINDHI_INDIA = 0x01;
pub const SINDHI_PAKISTAN = 0x02;
pub const SINDHI_AFGHANISTAN = 0x02;
pub const SINHALESE_SRI_LANKA = 0x01;
pub const SOTHO_NORTHERN_SOUTH_AFRICA = 0x01;
pub const SLOVAK_SLOVAKIA = 0x01;
pub const SLOVENIAN_SLOVENIA = 0x01;
pub const SPANISH = 0x01;
pub const SPANISH_MEXICAN = 0x02;
pub const SPANISH_MODERN = 0x03;
pub const SPANISH_GUATEMALA = 0x04;
pub const SPANISH_COSTA_RICA = 0x05;
pub const SPANISH_PANAMA = 0x06;
pub const SPANISH_DOMINICAN_REPUBLIC = 0x07;
pub const SPANISH_VENEZUELA = 0x08;
pub const SPANISH_COLOMBIA = 0x09;
pub const SPANISH_PERU = 0x0a;
pub const SPANISH_ARGENTINA = 0x0b;
pub const SPANISH_ECUADOR = 0x0c;
pub const SPANISH_CHILE = 0x0d;
pub const SPANISH_URUGUAY = 0x0e;
pub const SPANISH_PARAGUAY = 0x0f;
pub const SPANISH_BOLIVIA = 0x10;
pub const SPANISH_EL_SALVADOR = 0x11;
pub const SPANISH_HONDURAS = 0x12;
pub const SPANISH_NICARAGUA = 0x13;
pub const SPANISH_PUERTO_RICO = 0x14;
pub const SPANISH_US = 0x15;
pub const SWAHILI_KENYA = 0x01;
pub const SWEDISH = 0x01;
pub const SWEDISH_FINLAND = 0x02;
pub const SYRIAC_SYRIA = 0x01;
pub const TAJIK_TAJIKISTAN = 0x01;
pub const TAMAZIGHT_ALGERIA_LATIN = 0x02;
pub const TAMAZIGHT_MOROCCO_TIFINAGH = 0x04;
pub const TAMIL_INDIA = 0x01;
pub const TAMIL_SRI_LANKA = 0x02;
pub const TATAR_RUSSIA = 0x01;
pub const TELUGU_INDIA = 0x01;
pub const THAI_THAILAND = 0x01;
pub const TIBETAN_PRC = 0x01;
pub const TIGRIGNA_ERITREA = 0x02;
pub const TIGRINYA_ERITREA = 0x02;
pub const TIGRINYA_ETHIOPIA = 0x01;
pub const TSWANA_BOTSWANA = 0x02;
pub const TSWANA_SOUTH_AFRICA = 0x01;
pub const TURKISH_TURKEY = 0x01;
pub const TURKMEN_TURKMENISTAN = 0x01;
pub const UIGHUR_PRC = 0x01;
pub const UKRAINIAN_UKRAINE = 0x01;
pub const UPPER_SORBIAN_GERMANY = 0x01;
pub const URDU_PAKISTAN = 0x01;
pub const URDU_INDIA = 0x02;
pub const UZBEK_LATIN = 0x01;
pub const UZBEK_CYRILLIC = 0x02;
pub const VALENCIAN_VALENCIA = 0x02;
pub const VIETNAMESE_VIETNAM = 0x01;
pub const WELSH_UNITED_KINGDOM = 0x01;
pub const WOLOF_SENEGAL = 0x01;
pub const XHOSA_SOUTH_AFRICA = 0x01;
pub const YAKUT_RUSSIA = 0x01;
pub const YI_PRC = 0x01;
pub const YORUBA_NIGERIA = 0x01;
pub const ZULU_SOUTH_AFRICA = 0x01;