Updated 2011-08-10 09:03:35 by YS

Purpose: for users and developers to list error messages they encounter in Tcl and for others to explain some of the possible causes (and solutions) for these msgs. See also Common Tk Error Messages and Possible Explanations.

In many cases, the Tcl error messages are so clear that by reading the words carefully, one can pretty much figure out what is needed. However, there are occasionally times when this is not the case. Also, sometimes the error msg in question is from the operating system, but it appears as though the error is coming from Tcl. This page is intended to provide some assistance in those cases.

From http://www.psg.com/~joem/tcl/faq.html#SectionD I start with these questions and answers:

  1. "not found" or "Command not found"

This error message comes from your shell, not Tcl. The script probably starts with a #! that is followed by a path to the Tcl interpreter that is too long for your system. Many Unix systems are limited to 32 characters (including the #!) in this regard. So, something like this will fail:
    #! /usr/home/homedir/very/long/path/tclsh

    # rest of script

You can either shorten the path by moving the tclsh executable to a different directory or by using symbolic links. Another option is to not specify the path at all. See the question "How do I make my script executable regardless of the location of tclsh?" for an example of how to do this.

  1. invalid command name "}"

You have probably commented out a line that ends with an open curly brace. See http://www.psg.com/~joem/tcl/faq.html#CommentStrangeness for more info.

Another common cause can be the difference between interactive and command modes for Tcl. When you start up a Tcl interpreter, get a prompt, and type in commands to Tcl, this is called interactive mode. In this mode, Tcl does a few extra things for you. For instance, if you type ls, and you have no proc called ls defined, Tcl will try to exec a command called ls. This sometimes misleads a new Tcl user into thinking that Tcl has ls defined. They then copy into a script file the same commands they typed in during interactive mode. This results in the user getting the error:
 invalid command name "ls"
     while executing
     (file "/tmp/t.tcl" line 3)

  1. missing close-brace

Your braces aren't balanced. Again, one likely, though perhaps non-obvious, reason is improperly commented lines. See Question 12.

  1. expected integer but got ...

This error occurs when the interpreter was trying to perform some mathematical operation that requires an integer value, but encountered a non-integer value. While this is pretty obvious when the value supplied is a floating point value or an alphabetic string, this error can be confusing when the value is something that may look like a valid integer - specifically numbers that have leading zeros. See the question How can I use numbers with leading zeros? for an explanation.

  1. "Undefined symbol: main" or similar

The message, which comes not from Tcl but from some tool in the build process, occurs when linking an application. It is probably because the application was written for a version of Tcl different from the one you are linking against.

Older versions of Tcl included a main function in the library (libtcl.a). This caused various problems, in particular with C++ programs, and it was removed starting with version 7.4b1. The application being linked with the Tcl library must now provide the main routine itself.

  1. "extra characters after close brace while executing" [confirm message text]

This error occurs when the user incorrectly codes a proc like this:
 proc test {intext}{
  puts "hello"

That is to say - neglects to put a space before the opening brace of the proc's body.

  1. "extra characters after close-quote"

This error can occur when there is no space between "if" and open brace "{" for example.
  if{$x == 1} {

  The correct way should be:

  if {$x == 1} {