{"record":{"id":"b8ee81210cb2cde6","repo":"puppetlabs/puppet","slug":"failed-to-get-user-name","errorCode":null,"errorMessage":"Failed to get user name","messagePattern":"Failed to get user name","errorType":"exception","errorClass":"Puppet::Util::Windows::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/adsi.rb","lineNumber":513,"sourceCode":"      expires && expires < Time.now\n    rescue WIN32OLERuntimeError => e\n      # This OLE error code indicates the property can't be found in the cache\n      raise e unless e.message =~ /8000500D/m\n\n      false\n    end\n\n    # UNLEN from lmcons.h - https://stackoverflow.com/a/2155176\n    MAX_USERNAME_LENGTH = 256\n    def self.current_user_name\n      user_name = ''.dup\n      max_length = MAX_USERNAME_LENGTH + 1 # NULL terminated\n      FFI::MemoryPointer.new(max_length * 2) do |buffer| # wide string\n        FFI::MemoryPointer.new(:dword, 1) do |buffer_size|\n          buffer_size.write_dword(max_length) # length in TCHARs\n\n          if GetUserNameW(buffer, buffer_size) == FFI::WIN32_FALSE\n            raise Puppet::Util::Windows::Error, _(\"Failed to get user name\")\n          end\n\n          # buffer_size includes trailing NULL\n          user_name = buffer.read_wide_string(buffer_size.read_dword - 1)\n        end\n      end\n\n      user_name\n    end\n\n    # https://docs.microsoft.com/en-us/windows/win32/api/secext/ne-secext-extended_name_format\n    NameUnknown           = 0\n    NameFullyQualifiedDN  = 1\n    NameSamCompatible     = 2\n    NameDisplay           = 3\n    NameUniqueId          = 6\n    NameCanonical         = 7\n    NameUserPrincipal     = 8","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/adsi.rb#L495-L531","documentation":"Raised on Windows when the Win32 GetUserNameW call fails inside Puppet::Util::Windows::User.current_user_name, which resolves the running process's user (for logging, ACL, and ownership decisions). It raises Puppet::Util::Windows::Error, appending the GetLastError details to the message.","triggerScenarios":"Calling current_user_name in a context where the process/token cannot report its user — effectively only under system-level failure such as security-subsystem breakage or severe resource exhaustion.","commonSituations":"Almost never observed on healthy machines; shows up in traces alongside other Win32 failures during incident debugging.","solutions":["Retry after a reboot; verify basic health with `whoami` from the same context.","Inspect the System event log and memory pressure; report upstream with the win32 error code from the message if persistent."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Util::Windows::User.current_user_name\nrescue Puppet::Util::Windows::Error\n  ENV['USERNAME'] # best-effort fallback\nend","preventionTips":["Cache the result; do not call in tight loops.","Guard Windows-specific helpers so non-Windows platforms skip them."],"tags":["puppet","windows","win32","ffi","user-name"],"backgroundTag":"win32-api-call-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}