Skip to content

Many calls use errno to look up error, but should be using GetLastError #30

@Taywee

Description

@Taywee

Description

errno is used instead of GetLastError, resulting in proper detection of an error, but often an incorrect error itself is thrown. According to the functions (for instance, ReadEventLog), the error information should be from GetLastError, not errno. I'm not sure if the other functions are supposed to be using errno or not.

Gem Version

0.6.7 on jruby 9.2.0.0

Windows Version

Windows 7

Replication Case

Before clearing the log

[38] pry(main)> Win32::EventLog.new('Media Center').total_records
=> 1
[39] pry(main)> Win32::EventLog.new('Media Center').read_last_event
=> #<struct Struct::EventLogStruct
 record_number=94,
 time_generated=2018-08-16 08:42:07 -0600,
 time_written=2018-08-16 08:42:07 -0600,
 event_id=0,
 event_type="information",
 category=0,
 source="MCUpdate",
 computer="windows7",
 user=nil,
 string_inserts=
  ["8:41:42 AM - Testing internet connection.\r\n8:41:59 AM - Connection established.\r\n8:42:04 AM - Retrieving Directory.\r\n8:42:05 AM - Processing Directory.\r\n8:42:06 AM - Processing of Directory is complete.\r\n8:42:06 AM - The MCEClientMaintenance package is already up to date.\r\n8:42:07 AM - Update successful.\r\n8:42:07 AM - Next update at 8/17/2018 7:15:09 AM.\r\n"],
 description=
  "8:41:42 AM - Testing internet connection.\r\n8:41:59 AM - Connection established.\r\n8:42:04 AM - Retrieving Directory.\r\n8:42:05 AM - Processing Directory.\r\n8:42:06 AM - Processing of Directory is complete.\r\n8:42:06 AM - The MCEClientMaintenance package is already up to date.\r\n8:42:07 AM - Update successful.\r\n8:42:07 AM - Next update at 8/17/2018 7:15:09 AM.\r\n\r\n">

After clearing the log

[40] pry(main)> Win32::EventLog.new('Media Center').total_records
=> 0
[41] pry(main)> Win32::EventLog.new('Media Center').read_last_event
Errno::ENAMETOOLONG: File name too long - ReadEventLog
from C:/jruby-9.2.0.0/lib/ruby/gems/shared/gems/win32-eventlog-0.6.7/lib/win32/eventlog.rb:750:in `read_last_event'
[42] pry(main)>

Which is clearly the wrong error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions