Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 268945fb5d6fd07cd5ca190160c1915221c827433d861d889363ce41117ad069
Ticket: b8f575aa2398b0e44b5a037326b9d75037e2da4a
Tcl 9: eof erroneously flagged with not reported encoding read error
User & Date: pointsman on 2022-12-09 13:05:54
Changes

  1. icomment:
    Even if it seemed clear to me that despite of -strictencoding true -nocomplainencoding false neither the [read] itself nor [eof] giving no sign of error could not really be how this is supposed to work -- I have to confess that I haven't a clear picture about how this in fact is supposed to work.
    
    May I ask: Since I gave -strictencoding true -nocomplainencoding false - that is, I made clear that I wanted to be informed about encoding errors - why doesn't the first [read] raised error in the first place?
    
    It is true that immediately raising error atm doesn't provide information about where in the input the error is (byte or char position). Or did I have missed something here?
    
    But even if the behaviour is changed so that [eof] returns 0 to signal that something happend (as proposed here) that would mean that I need a combination of while {![eof]} {} and a catch/try around the [read], something like
    
    ```
    fd [open "somefile"]
    set data ""
    while {![eof $fd]} {
      if {[catch {append data [read $fd]}]} {
        # Handle error
      }
    }
    ```
    
    It's this how this is supposed to work. 
    
    Isn't this a bit awkwarded / convoluted? Especially given that most programmers are typically don't expect to have to check [eof] if they want to read the whole data out of a file in one go with [read $fd].
    
  2. login: "pointsman"
  3. mimetype: "text/x-markdown"