Skip to content

Resolve errors when accessing Unix-dependent properties such as User, Group, UnixMode, Size, etc. #319

@krymtkts

Description

@krymtkts

Resolve errors when accessing Unix-dependent properties such as User, Group, UnixMode, Size, etc.
Currently, suppress errors by catching them with try ... with by #318 .

PS /mnt/c/Users/takatoshi> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Ubuntu 20.04.5 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS /mnt/c/Users/takatoshi> $ErrorView = 'DetailedView'
PS /mnt/c/Users/takatoshi> get-ChildItem | pocof -Layout TopDownHalf ':Size 1'
query>:Size 1                                                                                                                                                                                                                                                  match and [0]
Exception             :
    Type            : System.AggregateException
    InnerExceptions :
        Type           : System.Management.Automation.GetValueInvocationException
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Exception getting "Size": "There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size"
                HResult : -2146233087
            CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : ScriptgetValueInvalidOperationException
        TargetSite     :
            Name          : InvokeGetter
            DeclaringType : psscriptproperty
            MemberType    : Method
            Module        : System.Management.Automation.dll
        Message        : Exception getting "Size": "There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size"
        InnerException :
            Type        : System.Management.Automation.PSInvalidOperationException
            ErrorRecord :
                Exception             :
                    Type    : System.Management.Automation.ParentContainsErrorRecordException
                    Message : There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size
                    HResult : -2146233087
                CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
                FullyQualifiedErrorId : ScriptBlockDelegateInvokedFromWrongThread
            TargetSite  :
                Name          : GetContextFromTLS
                DeclaringType : scriptblock
                MemberType    : Method
                Module        : System.Management.Automation.dll
            Message     : There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size
            Source      : System.Management.Automation
            HResult     : -2146233079
            StackTrace  :
   at System.Management.Automation.ScriptBlock.GetContextFromTLS()
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
   at System.Management.Automation.PSScriptProperty.InvokeGetter(Object scriptThis)
        Source         : System.Management.Automation
        HResult        : -2146233087
        StackTrace     :
   at System.Management.Automation.PSScriptProperty.InvokeGetter(Object scriptThis)
   at [email protected](Entry entry)
   at lambda_method453(Closure, Entry)
   at System.Linq.Parallel.OrderPreservingPipeliningSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    Message         : One or more errors occurred. (Exception getting "Size": "There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size")
    TargetSite      :
        Name          : QueryEnd
        DeclaringType : System.Linq.Parallel.QueryTaskGroupState, System.Linq.Parallel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
        MemberType    : Method
        Module        : System.Linq.Parallel.dll
    InnerException  :
        Type           : System.Management.Automation.GetValueInvocationException
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Exception getting "Size": "There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size"
                HResult : -2146233087
            CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : ScriptgetValueInvalidOperationException
        TargetSite     :
            Name          : InvokeGetter
            DeclaringType : psscriptproperty
            MemberType    : Method
            Module        : System.Management.Automation.dll
        Message        : Exception getting "Size": "There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size"
        InnerException :
            Type        : System.Management.Automation.PSInvalidOperationException
            ErrorRecord :
                Exception             :
                    Type    : System.Management.Automation.ParentContainsErrorRecordException
                    Message : There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size
                    HResult : -2146233087
                CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
                FullyQualifiedErrorId : ScriptBlockDelegateInvokedFromWrongThread
            TargetSite  :
                Name          : GetContextFromTLS
                DeclaringType : scriptblock
                MemberType    : Method
                Module        : System.Management.Automation.dll
            Message     : There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to invoke was: $this.UnixStat.Size
            Source      : System.Management.Automation
            HResult     : -2146233079
            StackTrace  :
   at System.Management.Automation.ScriptBlock.GetContextFromTLS()
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
   at System.Management.Automation.PSScriptProperty.InvokeGetter(Object scriptThis)
        Source         : System.Management.Automation
        HResult        : -2146233087
        StackTrace     :
   at System.Management.Automation.PSScriptProperty.InvokeGetter(Object scriptThis)
   at [email protected](Entry entry)
   at lambda_method453(Closure, Entry)
   at System.Linq.Parallel.OrderPreservingPipeliningSpoolingTask`2.SpoolingWork()
   at System.Linq.Parallel.SpoolingTaskBase.Work()
   at System.Linq.Parallel.QueryTask.BaseWork(Object unused)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    Source          : System.Linq.Parallel
    HResult         : -2146233088
    StackTrace      :
   at System.Linq.Parallel.QueryTaskGroupState.QueryEnd(Boolean userInitiatedDispose)
   at System.Linq.Parallel.OrderPreservingPipeliningMergeHelper`2.OrderedPipeliningMergeEnumerator.ThrowIfInTearDown()
   at System.Linq.Parallel.OrderPreservingPipeliningMergeHelper`2.OrderedPipeliningMergeEnumerator.MoveNext()
   at System.Linq.Parallel.QueryOpeningEnumerator`1.MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.Truncate@1084.GenerateNext(IEnumerable`1& next) in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 1087
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl() in D:\a\_work\1\s\src\FSharp.Core\seqcore.fs:line 488
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System.Collections.IEnumerator.MoveNext() in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 111
   at Microsoft.FSharp.Collections.SeqModule.ToArray[T](IEnumerable`1 source) in D:\a\_work\1\s\src\FSharp.Core\seq.fs:line 1028
   at Microsoft.FSharp.Collections.ArrayModule.OfSeq[T](IEnumerable`1 source) in D:\a\_work\1\s\src\FSharp.Core\array.fs:line 1561
   at Pocof.SelectPocofCommand.Invoke[a](IEnumerable`1 input)
   at <StartupCode$pocof>[email protected](IEnumerable`1 input)
   at Pocof.Screen.Buff.WriteScreen(InternalState state, ParallelQuery`1 entries, FSharpResult`2 props)
   at Pocof.Pocof.renderOnce(RenderHandler handler, Buff buff)
   at Pocof.Pocof.Periodic.Render()
   at [email protected](Unit unitVar0)
   at Pocof.SelectPocofCommand.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [Select-Pocof], AggregateException
FullyQualifiedErrorId : System.AggregateException,Pocof.SelectPocofCommand
InvocationInfo        :
    MyCommand        : Select-Pocof
    ScriptLineNumber : 1
    OffsetInLine     : 17
    HistoryId        : 8
    Line             : get-ChildItem | pocof -Layout TopDownHalf ':Size 1'
    Statement        : pocof -Layout TopDownHalf ':Size 1'
    PositionMessage  : At line:1 char:17
                       + get-ChildItem | pocof -Layout TopDownHalf ':Size 1'
                       +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : pocof
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions