Skip to content

Commit 8260059

Browse files
authored
use correct variable in windowserror description (#34067)
1 parent fe85b4a commit 8260059

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

base/error.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ end
179179
Like [`systemerror`](@ref), but for Windows API functions that use [`GetLastError`](@ref Base.Libc.GetLastError) to
180180
return an error code instead of setting [`errno`](@ref Base.Libc.errno).
181181
"""
182-
windowserror(p, b::Bool; extrainfo=nothing) = b ? windowserror(b, extrainfo=extrainfo) : nothing
182+
windowserror(p, b::Bool; extrainfo=nothing) = b ? windowserror(p, extrainfo=extrainfo) : nothing
183183
windowserror(p, code::UInt32=Libc.GetLastError(); extrainfo=nothing) = throw(Main.Base.SystemError(string(p), 0, WindowsErrorInfo(code, extrainfo)))
184184

185185

base/libc.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,15 @@ function FormatMessage end
313313
if Sys.iswindows()
314314
GetLastError() = ccall(:GetLastError, stdcall, UInt32, ())
315315

316-
function FormatMessage(e=GetLastError())
316+
FormatMessage(e) = FormatMessage(UInt32(e))
317+
function FormatMessage(e::UInt32=GetLastError())
317318
FORMAT_MESSAGE_ALLOCATE_BUFFER = UInt32(0x100)
318319
FORMAT_MESSAGE_FROM_SYSTEM = UInt32(0x1000)
319320
FORMAT_MESSAGE_IGNORE_INSERTS = UInt32(0x200)
320321
FORMAT_MESSAGE_MAX_WIDTH_MASK = UInt32(0xFF)
321322
lpMsgBuf = Ref{Ptr{UInt16}}()
322323
lpMsgBuf[] = 0
323-
len = ccall(:FormatMessageW, stdcall, UInt32, (Cint, Ptr{Cvoid}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Cvoid}),
324+
len = ccall(:FormatMessageW, stdcall, UInt32, (UInt32, Ptr{Cvoid}, UInt32, UInt32, Ptr{Ptr{UInt16}}, UInt32, Ptr{Cvoid}),
324325
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
325326
C_NULL, e, 0, lpMsgBuf, 0, C_NULL)
326327
p = lpMsgBuf[]

test/errorshow.jl

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,50 @@ using Random, LinearAlgebra
55
# For curmod_*
66
include("testenv.jl")
77

8+
9+
@testset "SystemError" begin
10+
err = try; systemerror("reason", Cint(0)); false; catch ex; ex; end::SystemError
11+
errs = sprint(Base.showerror, err)
12+
@test startswith(errs, "SystemError: reason: ")
13+
14+
err = try; systemerror("reason", Cint(0), extrainfo="addend"); false; catch ex; ex; end::SystemError
15+
errs = sprint(Base.showerror, err)
16+
@test startswith(errs, "SystemError (with addend): reason: ")
17+
18+
err = try
19+
Libc.errno(0xc0ffee)
20+
systemerror("reason", true)
21+
false
22+
catch ex
23+
ex
24+
end::SystemError
25+
errs = sprint(Base.showerror, err)
26+
@test startswith(errs, "SystemError: reason: ")
27+
28+
err = try; Base.windowserror("reason", UInt32(0)); false; catch ex; ex; end::SystemError
29+
errs = sprint(Base.showerror, err)
30+
@test startswith(errs, Sys.iswindows() ? "SystemError: reason: " :
31+
"SystemError (with Base.WindowsErrorInfo(0x00000000, nothing)): reason: ")
32+
33+
err = try; Base.windowserror("reason", UInt32(0); extrainfo="addend"); false; catch ex; ex; end::SystemError
34+
errs = sprint(Base.showerror, err)
35+
@test startswith(errs, Sys.iswindows() ? "SystemError (with addend): reason: " :
36+
"SystemError (with Base.WindowsErrorInfo(0x00000000, \"addend\")): reason: ")
37+
38+
@static if Sys.iswindows()
39+
err = try
40+
ccall(:SetLastError, stdcall, Cvoid, (UInt32,), 0x00000000)
41+
Base.windowserror("reason", true)
42+
false
43+
catch ex
44+
ex
45+
end::SystemError
46+
errs = sprint(Base.showerror, err)
47+
@test startswith(errs, "SystemError: reason: ")
48+
end
49+
end
50+
51+
852
cfile = " at $(@__FILE__):"
953
c1line = @__LINE__() + 1
1054
method_c1(x::Float64, s::AbstractString...) = true
@@ -593,4 +637,4 @@ for (func,str) in ((TestMethodShadow.:+,":+"), (TestMethodShadow.:(==),":(==)"),
593637
e
594638
end::MethodError
595639
@test occursin("You may have intended to import Base.$str", sprint(Base.showerror, ex))
596-
end
640+
end

0 commit comments

Comments
 (0)